JSON Parser from Scratch - Problem
Build a complete JSON parser from scratch that can handle all JSON data types including objects, arrays, strings, numbers, booleans, and null values.
Your parser should take a valid JSON string as input and return the parsed data structure. The parser must correctly handle:
- Objects:
{"key": "value"} - Arrays:
[1, 2, 3] - Strings:
"hello world" - Numbers:
42,-17,3.14 - Booleans:
true,false - Null:
null
The parser should properly handle nested structures and whitespace. Return the parsed data in the appropriate format for your language.
Input & Output
Example 1 — Simple Object
$
Input:
jsonString = "{\"name\": \"John\", \"age\": 30}"
›
Output:
{"name": "John", "age": 30}
💡 Note:
Parse a JSON object with string and number values. The parser identifies the opening brace, parses each key-value pair, and constructs the object.
Example 2 — Array with Mixed Types
$
Input:
jsonString = "[1, \"hello\", true, null]"
›
Output:
[1, "hello", true, null]
💡 Note:
Parse an array containing different JSON data types: number, string, boolean, and null. Each element is parsed according to its type.
Example 3 — Nested Structure
$
Input:
jsonString = "{\"user\": {\"id\": 123, \"active\": true}}"
›
Output:
{"user": {"id": 123, "active": true}}
💡 Note:
Parse nested objects where the value of 'user' is itself an object. The recursive parser handles the nesting naturally.
Constraints
- 1 ≤ jsonString.length ≤ 104
- Input is guaranteed to be valid JSON
- May contain nested objects and arrays up to depth 100
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code