FastPrepNested JSON Schema Validator
Problems/Nested JSON Schema Validator

Nested JSON Schema Validator

Pinterest logoPinterest● HardFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Pinterest onsite interview. The report describes checking a nested JSON schema with DFS, from string inputs. It does not give the grammar, the matching rules, the constraints, or the output format. This version uses a restricted form of JSON with fixed rules, and it keeps the recursive checking from the report. Our version is about 84% the same as the reported question.

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.

More Pinterest Onsite Interview questions

  • Minimum Bus Routes to a DestinationPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Delete and Compact a Forest SubtreePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Filter Pins by Excluded IDsONSITE INTERVIEW · Seen Oct 2026
  • Top-Scoring Items in a Time WindowONSITE INTERVIEW · Seen Oct 2026
  • Optimal Account BalancingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Escape Room LeaderboardPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Policy Violation Set ChecksONSITE INTERVIEW · Seen Sep 2026
  • Shortest Sequence of Source SubsequencesONSITE INTERVIEW · Seen Sep 2026
  • Insert Addition and Multiplication OperatorsONSITE INTERVIEW · Seen Sep 2026
  • Unique Active Pins by Time SegmentONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Validate Nested JSON Against a SchemaBenchling · ONSITE INTERVIEWBenchling interview questions
  • Validate a Nested Object Against a SchemaConfluent · ONSITE INTERVIEWConfluent interview questions
  • Nested Substitutions with Cycle DetectionKikoff · PHONE SCREENKikoff interview questions
  • Spreadsheet Formula DependenciesAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Toy Language Generic Return-Type InferenceOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Feature Flags with Rules, Dependencies and ExposurePerplexity AI · ONSITE INTERVIEWPerplexity AI interview questions
  • Template Variable ExpansionGoogle · ONSITE INTERVIEWGoogle interview questions
  • JSON Path Lookup with Implicit Array WildcardsMongoDB · ONSITE INTERVIEWMongoDB interview questions
  • Filesystem Hash TreeCursor · PHONE SCREEN · ONSITE INTERVIEWCursor interview questions
  • Domain Weight CalculationAmazon · ONSITE INTERVIEW

Pinterest interview experiences

  • Pinterest Experienced MLE Phone Screen: 1 Experience
All Pinterest interview questionsSee Pinterest hiring insights
Saved
class Solution {
    public boolean validateNestedJsonSchema(String schema, String document) {
        // Write your code here.
    }
}

Not a valid String

Checking account…