In Go's JSON package, I saw there are marshal
, decode
and other functions.
I thought that decode
is the opposite to marshal
, but latter realized that I might be wrong.
I think the fundamental question that I have is:
What are the relations and differences between marshall/unmarshal, encoding/decoding, and serialization/deserialization for JSON?
Thanks.
See an example here Why are json package's Decode and Marshal methods used here?
I would personally say all those terms are synonyms though less so with encoding/decoding. In Go Marshal and Unmarshal happen to be the terms that are used to describe converting json in a string form to an object and vice versa. However in C# these same methods are called serialize and deserialize, as far as I know that terminology isn't in Go at all (at least not in any std lib).
Encoding can be used as an adjective to describe the format in which some data is stored, the most common use is probably character encoding (UTF-8). In Go it's also used as a noun to describe objects that can unmarshal/marshal json. Marshal/Unmarshal are always used as verbs, you take that action on the json.
Encoding is also used in Go to refer to a larger category of packages that deal with the conversion from one encoding to another.
If you told me you were marshalling, marshalling, deserializing or serializing some object or json I would understand exactly what you meant. If you said you were json encoding an object I would ask a clarifying question. If you said the "response is json encoded" I would get what you mean though I would think it's odd that you used those words rather than just saying "the response is json". Hope that is more or less the information you're looking for.
Oh also, just for more clarity
Unmarshal == deserialize == decode
Marshal == serialize == encode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With