Personal project · Rust cohort
Rust JSON Parser
A custom tokenizer and parser supporting nested arrays and objects, typed JSON values, structured errors and JSON formatting. I developed it in a Rust cohort and revised it based on cohort feedback.
View source- Engagement
- Personal learning project
- Tests
- 105 test functions in the repository
- Status
- Learning project, not intended for production use
From text to typed values
Input
{
"name": "Ada",
"tags": ["rust", "json"],
"active": true
}Parsed structure
Object (3 keys)
├ name: String "Ada"
├ tags: Array (2 items)
│ ├ String "rust"
│ └ String "json"
└ active: Bool trueHow it works
1 · Tokenization
The tokenizer reads characters and produces tokens: braces, brackets, strings, numbers, literals and separators.
2 · Recursive parsing
The parser builds typed values from tokens, calling itself for each nested array or object.
3 · Explicit errors
Places that assumed well-formed input now return a structured error instead of panicking.
// Before: assumes another character exists
let ch = chars.next().unwrap();
// After: the caller receives a structured error
let ch = chars.next().ok_or(ParseError::UnexpectedEnd)?;Playground
Proposed featureNot built yet. This preview uses the browser’s own JSON parser to show the interaction; it does not run the Rust code.
Turn on JavaScript to edit the example. This is its starting state.
Parsed output
Couldn’t parse this input
Object (2 keys)
user: Object (2 keys)
name: String "Ada"
tags: Array (2 items)
[0]: String "rust"
[1]: String "json"
items: Array (3 items)
[0]: Number 1
[1]: Array (2 items)
[0]: Number 2
[1]: Number 3
[2]: Null