Reported August 2026
Pinterestrecursion

Nested JSON Schema Validator

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

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

The data structure here is a tree, and you build it yourself. Pinterest's Nested JSON Schema Validator was reported in August 2026, and it looks scary only because you get two raw strings instead of parsed objects. No JSON library to lean on, so you write a small recursive descent parser for both inputs, then compare the two trees node by node. If the parsing feels like too much to write cold, StealthCoder runs invisibly during the live OA as a safety net. But the whole thing is about 60 lines once you see the shape.

The problem

You are given two strings, schema and document. Each string contains valid JSON from the restricted grammar below. Return true exactly when the complete document matches the schema.
A schema node is one of:
"string", "integer", or "boolean" for a primitive JSON value;
{"array": childSchema} for an array whose every element matches childSchema;
{"object": {"field": fieldSchema,...}} for an object.
An object matches only when it has exactly the declared fields: every declared field is present and no undeclared field is present. Field order does not matter. An empty array matches any array schema. The document grammar contains strings, integers, booleans, arrays, and objects; it does not contain null or decimal numbers.
The two inputs may contain JSON whitespace. Strings and field names use only letters, digits, spaces, underscores, and hyphens, so escaped characters do not occur. Both inputs are guaranteed to be syntactically valid, every object has unique keys, and schema is a valid schema.

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

Examples
Example 1
schema = "{\"object\":{\"profile\":{\"object\":{\"name\":\"string\",\"active\":\"boolean\"}},\"scores\":{\"array\":\"integer\"}}}"
document = "{\"profile\":{\"name\":\"Ada\",\"active\":true},\"scores\":[3,5]}"
return = true
Every required field is present with the exact recursive type, and every score is an integer.
Example 2
schema = "{\"object\":{\"profile\":{\"object\":{\"name\":\"string\",\"active\":\"boolean\"}}}}"
document = "{\"profile\":{\"name\":\"Ada\",\"active\":\"true\"}}"
return = false
The value of active is a string, not a JSON boolean.
Example 3
schema = "{\"object\":{\"user\":{\"object\":{\"id\":\"integer\"}}}}"
document = "{\"user\":{\"id\":7,\"name\":\"Lin\"}}"
return = false
Object validation is exact, so the undeclared nested field name makes the document invalid.

Constraints
1 <= schema.length, document.length <= 20000
The nesting depth of either input is at most 100.
The document contains at most 10000 JSON nodes.
Every integer is between -10^9 and 10^9, inclusive.
Inputs satisfy the restricted, valid JSON guarantees in the statement.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is to split the job in two. First, write one parser that turns a JSON string into nested structures: strings, integers, booleans, lists, and maps. Skip whitespace, read a value by looking at the current character, and recurse for arrays and objects. The same parser handles both schema and document. Second, write validate(schemaNode, docNode). A schema string means check the primitive type. A map with key array means the doc must be a list and every element must validate. A map with key object means the doc must be a map with exactly the same key set, then recurse per field. The pitfall is booleans versus integers if your language treats true as a number, so check the boolean type first. Also watch the empty array case, which always passes. Depth is 100, so recursion is fine. If you blank on the parser mid-OA, StealthCoder is the hedge that gets you unstuck.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Nested JSON Schema Validator 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 for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Pinterest reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Nested JSON Schema Validator FAQ

How hard is the Pinterest Nested JSON Schema Validator really?+

Medium. The logic is simple recursion, but you have to hand-write a JSON parser first, and that's where people burn time. If you've written a recursive descent parser before, it's quick. If not, expect most of your time to go into parsing, not validation.

What's the trick to solving it?+

Parse both strings into the same tree structure with one parser, then run a recursive validate function over the two trees. Keeping parsing and validation separate makes both parts short and easy to debug.

What's the most common bug?+

Mixing up booleans and integers, and forgetting that object matching is exact. You need the same key set, not just all declared keys present. Extra fields in the document must fail, as Example 3 shows.

Can I use a built-in JSON library?+

The problem gives you raw strings and says nothing about libraries, so don't count on it. Writing your own small parser is safer, and the restricted grammar (no null, no decimals, no escapes) keeps it short.

How do I prepare in 48 hours?+

Practice writing a recursive descent parser for a tiny grammar, then a recursive comparison over two trees. Test the empty array, nested objects, key order differences, and a boolean where an integer is expected. That covers nearly every edge here.

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

OA at Pinterest?
Invisible during screen share
Get it