Working with JSON
JSON is an acronym for JavaScript Object Notation. It is a popular format for data interchange because JSON objects closely resemble structured types (struct
s in Go), and it is text-based encoding, making the encoded data human-readable. It supports arrays, objects (name-value pairs), and relatively few basic types (strings, numbers, booleans, and null
). These properties make JSON a fairly easy format to work with.
Encoding refers to the process of transforming data elements into a sequence of bytes. When you encode (or marshal) data elements in JSON, you create a textual representation of those data elements while following JSON syntax rules. The reverse process, decoding (or unmarshaling) assigns JSON values to Go objects. The encoding process is lossy: you have to describe data values as text, and that is not always obvious for complex data types. When you decode such data, you have to know how to interpret the textual representation so you can parse the JSON...