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:
truefalsenull - 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.