Skip to main content

JSON Structure by Hand

intermediate13 min readLesson 88 of 180

The JSON grammar subset, flat-object extraction, and the two violations that cause most JSON bugs.

JSON: reading structure without a library

In the sandbox you have no Jackson/Gson โ€” and that is a feature: writing a minimal parser teaches the format's grammar. The subset we handle:

{ "name": "ann", "age": 31, "active": true, "tags": ["a", "b"] }
  • object: { key : value (, key : value)* } โ€” keys are strings
  • string: " chars " with \" \\ escapes
  • number: integer or decimal
  • literals: true false null
  • array: [ value (, value)* ]

Rather than a full recursive-descent parser, you'll practice flat-object extraction: find "key" at depth 0 and read its value โ€” enough for config-style objects, honest about skipping nesting/arrays-in-objects.

The lesson to keep: JSON's grammar is small; most JSON bugs are unescaped quotes and trailing commas โ€” both are grammar violations, so a by-hand parser surfaces them loudly.

Now practice

I/O & Formats LabA rule-respecting CSV scanner and writer, and flat JSON extraction without a library.3 challenges ยท ยท ~40 min