Summary
In this chapter, we studied what JSON is and how we can use Go to store JSON in our structs.
JSON is used by many programming languages including Go. JSON is made up of key-value pairs. These key-value pairs can be any of the following types: string, number, object, array, Boolean, or null.
Go's standard library provides many capabilities that make working with JSON easy. This includes the ability to decode JSON data into structs. It also has the ability to encode structs into JSON.
We have seen that, through the use of JSON tags, we have greater flexibility and control over how the encoding and decoding of JSON occurs. These tags give us the ability to name the JSON key name, ignore fields and not encode them into JSON, and omit fields when they are empty.
The Go standard library gives us the ability to determine how to print in an easy to read format by using the json.MarshalIndent()
function. We have also seen how to decode JSON structures when we do not...