Design a Json Parser from scratch
MediumLet's build a JSON parser from scratch. JSON (JavaScript Object Notation) is a lightweight data-interchange format that's easy for humans to read and write, and easy for machines to parse and generate. Almost every modern application interacts with JSON in some way, making a solid understanding of its parsing mechanics invaluable.
This problem focuses on designing and implementing a JSON parser that can take a string as input and represent it as an in-memory object model. We are aiming for a parser which:
- Correctly parses valid JSON strings.
- Handles different data types in JSON: strings, numbers, booleans, nulls, arrays, and nested objects.
- Reports meaningful errors for invalid JSON strings (e.g., unexpected characters, missing quotes, etc.).
- Is designed in a modular and extensible way.
This exercise is not about leveraging existing JSON parsing libraries. The goal is to understand the underlying principles and trade-offs involved in creating one.
Requirements
Think like an Architect
Before revealing the requirements, imagine you're in the interview right now."How would you clarify the scope with your interviewer?"