FastPrepRestricted JSON Parser
Problems/Restricted JSON Parser

Restricted JSON Parser

Old Mission logoOld Mission● HardFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Old Mission phone screen for a full-time role. The report names a C++ JSON-parser task. It leaves out the grammar it supports and the output format. We filled those in.

Our version is about 78% the same as the reported question.

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.

More Old Mission interview questions

  • Implement an Unordered MapPHONE SCREEN · Seen Dec 2022
  • Merging PalindromesOA · Seen Mar 2024

Similar questions at other companies

  • Arithmetic Expression EvaluatorMicrosoft · PHONE SCREENMicrosoft interview questions
  • Toy Language Generic Return-Type InferenceOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Basic Calculator with Multiplication and ParenthesesBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Remove Parentheses from a Plus-Minus ExpressionOracle · PHONE SCREENOracle interview questions
  • Parse Nested Message TypesApplied Intuition · PHONE SCREENApplied Intuition interview questions
  • Decode StringCompass International Holdings · PHONE SCREENCompass International Holdings interview questions
  • Positive-Integer Expression EvaluationJane Street · PHONE SCREENJane Street interview questions
  • Calculator with ParenthesesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Recursive Nested JSON Key SearchMongoDB · PHONE SCREENMongoDB interview questions
  • Flatten JSON With Array IndicesAdobe · PHONE SCREENAdobe interview questions

Interview reports that mention this question

  • Old Mission SWE OA and Interview Questions: 14 Experiences

Old Mission interview experiences

  • Old Mission Quant Trader and New Grad OA Questions: 7 Experiences
  • Old Mission Junior Quant Trader OA Guide
See Old Mission hiring insights
Saved
class Solution {
    public String normalizeJson(String text) {
      // Write your code here.
    }

}
Checking account…