...

/

The JSON Data Format

The JSON Data Format

This lesson discusses specifically the JSON type of data, and how Go reads and writes data in the JSON format efficiently.

We'll cover the following...

Introduction #

Structs can contain binary data; if this were printed as the text, it would not be readable for a human. Moreover, the data does not include the name of the struct field, so we don’t know what the data means. To remedy this, several formats have been devised, which transform the data into plain text, but annotated by their field names, so humans can read and understand the data.

svg viewer

Data in these formats can be transmitted over a network. In this way, the data is platform-independent and can be used as input/output in all kinds of applications, no matter what the programming language or the operating system is. The following terms are common here:

  • data structure to special format string = marshaling or encoding (before transmission at the sender or source)
  • special format string to data structure = unmarshaling or decoding (after transmission at the receiver or destination)

Marshaling is used to convert in-memory data to the special format (data -> string), ...