Reported December 2025
Benchlingrecursion

Validate Nested JSON Against a Schema

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

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

The Benchling OA reported in December 2025 hands you two JSON strings, a schema and a document, and asks if the document matches the schema exactly. The detail that bites is "exactly the declared fields": a missing field fails, and so does an extra one. There's no JSON library to lean on in spirit, so the real work is parsing nested objects and comparing them recursively. It's a recursive descent problem wearing a validation costume. If you blank on the parser mid-assessment, StealthCoder runs invisibly on your desktop as a safety net and gives you a working solution while you keep your cool.

The problem

You are given two strings, schema and document, containing valid JSON objects from the restricted grammar below. Return true exactly when the complete document matches the schema.
Each schema leaf is the descriptor "string" or "number".
Each non-leaf schema value is another schema object.
Each document leaf is a JSON string or integer, and each non-leaf value is another object.
An object matches only when it has exactly the declared fields: every schema field is present, no undeclared document field is present, and each value recursively matches its descriptor or nested schema. Field order does not matter.
The JSON-string interface is only a language-neutral execution adapter for the nested object structures used in the interview. Inputs may contain JSON whitespace. Keys and string values use letters, digits, spaces, underscores, and hyphens, so escaped characters do not occur. Both inputs are syntactically valid and every object has unique keys. In this exercise, the source's number descriptor means a signed integer.

Function
validateNestedObjectSchema(schema: String, document: String) → boolean

Examples
Example 1
schema = "{\"name\":\"string\",\"location\":{\"x\":\"number\",\"y\":\"number\"}}"
document = "{\"name\":\"bob\",\"location\":{\"x\":5,\"y\":6}}"
return = true
Both root fields are present, and every nested value has the declared type.
Example 2
schema = "{\"name\":\"string\",\"location\":{\"x\":\"number\"}}"
document = "{\"name\":\"bob\",\"location\":{\"x\":\"5\"}}"
return = false
location.x is a string, but its schema descriptor is number.
Example 3
schema = "{\"user\":{\"id\":\"number\"}}"
document = "{\"user\":{\"id\":7,\"name\":\"Lin\"}}"
return = false
The nested name field is undeclared, and matching requires the exact recursive shape.

Constraints
2 <= schema.length, document.length <= 20000.
The nesting depth of either object is at most 100.
Each object contains at most 10000 total fields.
Every document integer is between -10^9 and 10^9, inclusive.
Schema leaves are exactly "string" or "number"; document leaves are strings or integers.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Two steps. First, parse each string into a nested map with a small recursive descent parser. The grammar is tiny: objects, strings, integers, whitespace. No escapes, no arrays, no booleans, no null. Skip whitespace, read a quoted key, expect a colon, read a value that is either a quoted string, an integer with an optional minus sign, or a nested object. Second, compare recursively. If the schema value is the string "string", the document value must be a string. If it's "number", the document value must be an integer. If it's an object, the document value must be an object with the same key set, then recurse on each key. The pitfall is confusing a schema leaf with a document string leaf. Parse the schema leaf as a descriptor, not data. Also check key counts, not just that schema keys exist, or extra fields slip through. Depth is at most 100, so recursion is safe. StealthCoder is your hedge if the parser logic slips live in the OA.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Validate Nested JSON Against a Schema 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. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Benchling reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Validate Nested JSON Against a Schema FAQ

What's the trick in the Benchling nested JSON schema problem?+

Write a small recursive descent parser, then a recursive comparator. The grammar is restricted, so parsing is short. The comparator checks that key sets are identical, then matches leaves by type and recurses into nested objects. Most failures come from skipping the extra-field check.

Can I just use a built-in JSON parser?+

The problem text calls the JSON strings an execution adapter for nested object structures, and the function takes strings. If your language allows a standard JSON library in the assessment, it saves time. Don't count on it. Know how to hand-write the parser in case it's restricted.

What edge cases break most solutions?+

Extra document fields, missing schema fields, a string where a number is expected like "5" versus 5, negative integers, and whitespace between tokens. Also an empty nested object in both schema and document, which should match. Test each of these before submitting.

How hard is this really?+

Medium. No fancy algorithm, but it's implementation-heavy and easy to get wrong under time pressure. Parsing is the slow part. Comparison is about ten lines once you have maps. Complexity is linear in input length, which fits the 20000 character limit easily.

How do I prepare in 48 hours?+

Write a recursive descent parser for a tiny JSON subset from scratch once, with an index pointer and helper functions for whitespace, strings, integers, and objects. Then write the recursive matcher. Run the three examples from the problem and add cases for extra and missing keys.

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

OA at Benchling?
Invisible during screen share
Get it