core:encoding/json - Raw_JSON type for leaving parts of json unmarshalling unparsed #2768
Beefster09
started this conversation in
Proposals
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Go has the ability to leave parts of the json untouched when unmarshalling by giving a struct field the
RawMessage
type. While at first glance, this does not sound useful, there are some cases where it would be very helpful, such as being able to unmarshal a json object into one of a few structs depending on other nearby values.For example, consider the Tiled JSON format, which can encode tile layers as either an array of integers or a compressed base64 string, depending on the compression level (though this particular case could be solved by supporting arbitrary unions as well). Deferring the unmarshalling here would allow you to unmarshal it as a string when the tile layers are compressed or an array when uncompressed.
Beta Was this translation helpful? Give feedback.
All reactions