Systems & CLI · Intermediate

Build a JSON Parser

Write a hand-rolled lexer and recursive-descent parser that turns raw JSON text into native objects, arrays, numbers, and strings with precise error messages.

Intermediate12-20 hoursTypeScriptRust

You build a JSON parser that takes a raw string of JSON and produces an in-memory tree of native data structures, validating the input against the JSON grammar as it goes. The parser is split into a hand-written lexer that emits tokens (braces, brackets, colons, commas, strings, numbers, literals) and a recursive-descent parser that consumes those tokens to assemble objects, arrays, and scalars. When the input is malformed, it reports the line, column, and what it expected instead of failing silently. It is worth building because parsing is a foundational systems skill that demystifies how compilers, config loaders, and serializers actually work, and it forces you to handle tricky edge cases like nested escapes, Unicode, and exponential numbers. It is resume-worthy because it proves you can implement a real grammar from a specification rather than reaching for a library.

What you build

  • Tokenizes JSON into a stream of typed tokens with source positions
  • Parses objects, arrays, strings, numbers, booleans, and null via recursive descent
  • Handles string escapes including \n, \t, \uXXXX, and surrogate pairs
  • Supports nested structures to arbitrary depth
  • Reports errors with line and column numbers and the expected token
  • Rejects invalid input such as trailing commas and unquoted keys
  • Exposes a parse() function returning the native value or an error

What it teaches

  • Lexing and tokenization of a real grammar
  • Recursive-descent parsing and grammar-driven design
  • Error reporting with source positions
  • Handling string escapes and Unicode edge cases
  • Separating scanning from parsing for testability
  • Reading and implementing a formal specification

Sign in to open the build guide

Free account. Get the step-by-step build and every resource link.

Sign in to continue

Take it further

  • Pretty-print the parsed tree back into formatted JSON.
  • Add a streaming SAX-style mode that emits events instead of building a full tree.
  • Benchmark against the standard library parser and profile the hot paths.

More like this

All projects