About JSON
JSON stands for JavaScript Object Notation. This is a text-based format designed as an easy and light way to pass information between JavaScript systems.
A simple JSON document has the following format:
{ "name":"Mihalis", "surname":"Tsoukalos","country":"Greece" }
The preceding JSON document has three fields named name
, surname
, and country
. Each field has a single value.
However, JSON documents can have more complex structures with multiple depth levels.
Before seeing some code, I think that it would be very useful to talk about the encoding/json
Go package first. The encoding/json
package offers the Encode()
and Decode()
functions that allow the conversion of a Go object into a JSON document and vice versa. Additionally, the encoding/json
package offers the Marshal()
and Unmarshal()
functions that work similarly to Encode()
and Decode()
and are based on the Encode()
and Decode()
methods.
The main difference between Marshal()-Unmarshal()
and Encode()-Decode()
is that the former functions...