liveBook · Manning

JSON object

As explained in Learn Go with Pocket-Sized Projects

A JSON object is an unordered collection of named fields represented as string keys paired with JSON values.

A JSON object is an unordered collection of named fields. Each key is a string in double quotation marks, paired with a JSON value such as a number, string, Boolean, array, or another object. section 3.1.1

Nested book data

A book record can contain an author and title, while a person object contains a name and an array of books. Reordering an object's fields preserves the payload; reordering array elements does not. section 3.1.1

Listing 3.1 testdata/bookworms.json: Example of input file
[
  {
    "name": "Fadi",
    "books": [
      {
        "author": "Margaret Atwood",
        "title": "The Handmaid's Tale"
      },
      {
        "author": "Sylvia Plath",
        "title": "The Bell Jar"
      }
    ]
  },
  {
    "name": "Peggy",
    "books": [
      {
        "author": "Margaret Atwood",
        "title": "Oryx and Crake"
      },
      {
        "author": "Margaret Atwood",
        "title": "The Handmaid's Tale"
      },
      {
        "author": "Charlotte Brontë",
        "title": "Jane Eyre"
      }
    ]
  }
]

Inspect a complete JSON input file containing people, books, nested objects, strings, and arrays. section 3.1.1

Use JSON objects to exchange focused request data in an HTTP API:

  • Define a Go request structure with a JSON field tag, such as a GuessRequest containing the guess field. section 8.2.3
  • Decode the request body with json.NewDecoder and return a bad-request response when parsing fails. section 8.2.3

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Defines keys, values, nesting, and ordering, then demonstrates Go decoding without covering JSON internals.
Examples
Uses nested book records, a simple guess payload, and a Go handler that decodes request bodies.
What it assumes
Assumes Go structures and HTTP request handling while establishing JSON object syntax and value categories.
What you can do after
Apply JSON objects through Go structures and json.NewDecoder when sending or reading focused API request data.
How it connects
Connects JSON objects with arrays, Go structures, JSON decoding, HTTP, and REST API endpoints.

Also explained in

Compare how 7 books explain JSON object →

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.