FastPrepValidate a Nested Object Against a Schema
Problems/Validate a Nested Object Against a Schema

Validate a Nested Object Against a Schema

Confluent logoConfluent● HardFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A firsthand Full Stack interview report describes a frontend coding round that checks data against a schema with nested structures. The example uses name, location, x, and y with strings and numbers. The report leaves out what to do with bad input, whether extra fields are allowed, what kind of number it is, escaping, and argument types that work across languages. This version uses exact object shapes, signed integers for number, valid restricted JSON, and a JSON string as input. It keeps the reported task of checking recursively. Our version is about 88% the same as the reported question.

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.

More Confluent Onsite Interview questions

  • Implement tail -nPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Sudoku Board ValidationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Sudoku Puzzle SolverPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Sequential Phrase Search Across DocumentsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Bounded Combination Sum with Signed CandidatesONSITE INTERVIEW · Seen Oct 2026
  • Detect a Silent SensorONSITE INTERVIEW · Seen Sep 2026
  • Build an Inverted Document IndexONSITE INTERVIEW · Seen Sep 2026
  • Combination Sum with Unlimited ReuseONSITE INTERVIEW · Seen Sep 2026
  • Word Search Across DocumentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Windowed Key-Value MapPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025

Similar questions at other companies

  • Nested JSON Schema ValidatorPinterest · ONSITE INTERVIEWPinterest interview questions
  • Validate Nested JSON Against a SchemaBenchling · ONSITE INTERVIEWBenchling 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

Interview reports that mention this question

  • Confluent Coding and System Design Questions: 33 Questions

Confluent interview experiences

  • Confluent Older Concurrency Rounds: 12 Experiences (Part 2 of 2)
  • Confluent Concurrency Interviews: 28 Experiences (Part 1 of 2)
  • Confluent SWE OA, Coding and Design Interviews: 19 Experiences
  • Confluent File Manipulation Round (tail -n): 19 Experiences
All Confluent interview questionsSee Confluent hiring insights
Saved
class Solution {
    public boolean validateNestedObjectSchema(String schema, String document) {
        // Write your code here.
    }
}
Checking account…