Chapter Four · The Answers, Fluently

Reading JSON

The braces and brackets you have been reading on intuition, replaced with actual rules — and the rules are six kinds of value, taught honestly in one page. Then the craft: paths to any buried field, the four-step strategy that shrinks a fifty-station response to thirty seconds, the zero-null-missing distinction that keeps reports truthful, and the field guide to XML, CSV, and every other costume the same facts wear. After this chapter, no answer any API sends you will read as foreign.

Every answer in this book so far arrived dressed in braces and brackets, and you have been reading it on intuition. This chapter replaces intuition with the actual rules — and the rules turn out to be almost embarrassingly small. JSON's entire grammar is six kinds of value: objects, arrays, and four kinds of leaf. One page teaches all of it, honestly, with nothing held back for an advanced course.

The rest of the chapter is craft. Nesting, and the paths that name any buried field. The four-step strategy that takes a fifty-station response down to the thirty seconds it deserves — pretty-print, find the shape, read one element, let the rest exist. And the field guide to everything that is not JSON: XML still running the banks, CSV that spreadsheets open directly, and the Content-Type habit that turns "garbled garbage" into "correct answer, different clothes."

One specimen, fully annotated
{ } — an object
labelled facts, found by name: "capacity": 24
[ ] — an array
an ordered list, found by position: fifty stations, one per entry
The four leaves
"strings" in quotes · bare numbers · true / false · null, the deliberate nothing

Topics in This Chapter