JSON Parser LLD: Recursive Descent, Demystified in 200 Lines
A low-level design walkthrough of a JSON parser: the grammar as a call graph, recursive descent with a position cursor, escape and number handling, and error messages that point.
"Write a JSON parser." Of every question in this queue, this is the one that sounds hardest — parsers are compiler-class wizardry, surely? — and turns out to be the most mechanical once you see the trick. JSON's entire grammar fits on an index card, and there's a technique, recursive descent, that converts a grammar into code almost line for line. No tools, no theory, no magic: one cursor, six small functions that call each other. Two hundred lines from now you'll have a parser that handles nesting, escapes, unicode and scientific notation — and points a finger at the exact character where som…
What’s inside
Read this one free
Sign in and your first premium article is on us — read JSON Parser LLD: Recursive Descent, Demystified in 200 Lines free.