Reported May 2025
Old Missionrecursion

Restricted JSON Parser

Reported by candidates from Old Mission's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Old Mission OA. Under 2s to a working solution.
Founder's read

Old Mission reportedly sent this one in May 2025, and it looks scarier than it is. Strip the JSON branding and it's a recursive descent parser plus a serializer with one twist: sort object keys. If you've got an OA in the next day or two, this is a parsing problem, not an algorithms puzzle. The grammar is tiny, the input is guaranteed valid, and you never write error handling. If you blank on the structure mid-assessment, StealthCoder runs invisibly on your desktop and can hand you a working parser as a safety net.

The problem

Implement a parser for a restricted JSON language. Given a valid JSON string text, parse it without using a JSON library and return its canonical serialization.
The supported values are:
null, true, and false
integers
strings enclosed in double quotes
arrays
objects with string keys
Strings may contain the escapes \", \\, \n, and \t. Whitespace outside strings is insignificant.
The canonical serialization must:
contain no insignificant whitespace;
preserve array order;
sort every object's members by decoded key in lexicographic order;
serialize literals and integers in their ordinary JSON form; and
escape quotes, backslashes, newlines, and tabs inside strings.

Function
normalizeJson(text: String) → String

Examples
Example 1
text = " { \"b\" : [true, null], \"a\" : \"line\\nnext\" } "
return = "{\"a\":\"line\\nnext\",\"b\":[true,null]}"
The parser discards whitespace outside strings, sorts object keys so a precedes b, and emits the newline as \n.
Example 2
text = "[\"a\\\\b\",-12,{\"x\":false}]"
return = "[\"a\\\\b\",-12,{\"x\":false}]"
The backslash inside the first string remains escaped, and nested values retain their original order.

Constraints
1 <= text.length <= 20000
text is valid under the restricted grammar.
Nesting depth is at most 100.
Integers are in the range [-10^9, 10^9], use no leading zero except for 0, and never use negative zero.
Object keys are unique within each object.
Unescaped string characters are printable ASCII characters other than double quote and backslash.
Do not use a language-provided JSON parser or serializer.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is to parse into a tree, then serialize that tree. Keep a single index into the string. Write parseValue that skips whitespace, looks at the current char, and dispatches: n, t, f for literals, a quote for strings, [ for arrays, { for objects, otherwise a number. Arrays loop parseValue until ]. Objects loop key, colon, value until }. Store object members, sort by decoded key, then emit. Pitfalls: sort by the decoded key, not the raw escaped text. Handle escapes during string decoding (\", \\, \n, \t) and re-escape on output. Don't strip whitespace inside strings. Negative numbers need the minus sign handled. Depth is at most 100, so recursion is fine. Total cost is O(n log n) from sorting keys. If the recursion shape slips away live, StealthCoder is the hedge that keeps you moving.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Restricted JSON Parser cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Old Mission's OA.

Old Mission reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Restricted JSON Parser FAQ

What's the actual trick in the Old Mission restricted JSON parser?+

Separate parsing from serialization. Build a value tree with recursive descent, then write it back out. Sorting happens only when you serialize objects. Since input is guaranteed valid, you skip all error handling, which cuts the code roughly in half.

How hard is this problem really?+

Medium on paper, easy if you've written a recursive parser before. There's no clever algorithm. The difficulty is careful bookkeeping of the index, escapes, and sorting. Most failures come from small string-handling bugs, not from the overall design.

What should I sort object keys by?+

Sort by the decoded key, meaning after escapes are resolved. Then re-escape when writing output. Keys are unique per object, so you don't need tie-breaking. Plain string comparison in your language gives the lexicographic order you want for printable ASCII.

What edge cases break most solutions?+

Escaped backslashes right before a quote, whitespace inside strings that must be preserved, negative integers, nested empty arrays or objects, and forgetting that array order must stay unchanged. Test the two given examples plus an empty object and a deeply nested array.

How do I prepare for this in 48 hours?+

Write a recursive descent parser from scratch once, for arrays, objects, strings, and integers. Then add the escape handling and key sorting. Run it on the examples. One clean practice pass is enough because the grammar is small and the pattern repeats.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Old Mission.

OA at Old Mission?
Invisible during screen share
Get it