How it works...

This recipe provided us with examples of how to use the TOML, YAML, and JSON parsers to both write raw data to a go structure and read data out of it and into the corresponding format. Like the recipes in Chapter 1, I/O and Filesystems, we saw how common it is to quickly switch between []byte, string, bytes.Buffer, and other I/O interfaces.

The encoding/json package is the most comprehensive in providing encoding, marshaling, and other methods to work with the JSON format. We abstracted these away with our ToFormat functions, and it would be very simple to attach multiple methods such as this so that we could use a single structure that can quickly be converted into or from any of these types.

This recipe also touched upon structure tags and their use. The previous chapter also made use of these, and they're a common way to give hints to packages and libraries about how to treat data contained within a structure.