liveBook · Manning

JSON

As explained in Learn Go with Pocket-Sized Projects

JSON is a text-based data interchange format that represents structured values such as objects, arrays, strings, numbers, booleans, and null.

JSON is a text-based format for structured data. It stores key-value pairs: keys are strings, while values can be numbers, strings, arrays, booleans, or objects. Object fields are unordered; array elements are ordered. section 3.1.1

A practical Go workflow opens a JSON file, maps its structure to exported Go structs, and decodes it with encoding/json. Struct tags connect Go fields to JSON field names. section 3.1.3

When loading JSON in Go:

  • Define exported fields whose tagged structure matches the JSON data. section 3.1.3
  • Keep test data in a testdata directory, which the go tool ignores during compilation. section 3.1.1

Bookworm collections

A JSON array can contain objects with nested arrays: [{"name":"Fadi","books":[{"author":"Margaret Atwood","title":"The Handmaid's Tale"}]}]. Matching Go types use Bookworm with Name and Books fields, and Book with Author and Title fields, each connected by json tags.

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Defines values, ordering, tags, and decoding, but defers detailed parsing until HTTP response handling.
Examples
Demonstrates nested bookworm collections and an error response represented as {"error":"game over"}.
What it assumes
Assumes basic Go and command-line familiarity while teaching JSON values, Go field tags, exported fields, and file decoding.
What you can do after
Build JSON file loaders with encoding/json, tagged Go structs, json.Decoder, and explicit error handling.
How it connects
Connects JSON with Go structs, slices, maps, encoding/json, json.Decoder, json.Unmarshal, json.Encoder, and json.Marshal.

Also explained in

Compare how 35 books explain JSON →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.