Before you start: the parser map
Understand what you will build, how text flows, and how to progress without getting lost.
Before writing code
In this project you will build a program that receives JSON text and decides whether it represents a valid value. Valid input becomes the same value in compact JSON; invalid input produces a useful explanation. You do not need compiler theory: this lesson gives you the map first.
This is a reading stage. You do not need to run
shipcode testorshipcode submit. When you finish, choose Mark as read and continue.
What JSON is
JSON is text governed by precise rules. It has seven kinds of values: null, true, false, numbers, double-quoted strings, arrays, and objects. A JSON document contains exactly one root value. Thus null is valid but null true is not: extra content remains.
What parsing means
Parsing is not searching for words. It means reading from a position, recognizing one complete structure, and stopping exactly at the next character. Picture a finger—the cursor—moving through the input:
- skip permitted whitespace;
- inspect the current character to choose the kind of value;
- consume that complete value;
- skip trailing whitespace;
- verify that the document has ended.
Your central function answers: “what value starts here?” Arrays and objects ask that same question for every nested value; that is where recursion comes from.
What you will build
The work is split into six safe increments: literals and the cursor; numbers; strings and escapes; arrays; objects; and finally useful errors and safety limits. Each stage keeps everything that already works.
The project contract
Your program reads one JSON document from standard input (stdin). Valid input is written as compact JSON to stdout with exit code 0. Invalid input leaves stdout empty, writes a message containing error to stderr, and exits with a non-zero code.
A beginner-friendly workflow
For each practical stage: write a few examples, implement the smallest valid case, try one valid and one invalid input manually, check the acceptance criteria, run the stage tests, then fix one failure at a time. Tests specify observable behavior, not your internal design.
Do not use an existing JSON parser—the point is to build that part. You may use your language's lists, maps, strings and a serializer for the final output.
Before continuing
Make sure you can explain why a cursor is useful, why null true is invalid, and the different jobs of stdout and stderr. You do not need to memorize this page; return whenever a later stage uses these terms.