PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Applied

Validate JSON against a protobuf-like schema

Last updated: Mar 29, 2026

Quick Overview

This question evaluates schema validation and data-typing skills, including understanding of JSON primitive types, recursive message structures, and conformance to a protobuf-like schema with required and optional fields.

  • medium
  • Applied
  • Coding & Algorithms
  • Software Engineer

Validate JSON against a protobuf-like schema

Company: Applied

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given a simplified protobuf-like schema definition and a JSON value. Determine whether the JSON conforms to the schema. ## Schema model - A **schema** contains named **message types**. - Each message type contains **fields**. Each field has: - `name` (string) - `type` (one of: `int`, `float`, `bool`, `string`, or another message type name) - `optional` (boolean) Assume: - The JSON root is an **object** corresponding to a specified root message type. - A **required** field (`optional = false`) must be present. - An **optional** field may be missing. - If a field is present, its JSON value must match the expected type: - `int`: JSON number with no fractional part - `float`: JSON number (integer values are allowed) - `bool`: JSON boolean - `string`: JSON string - message type: JSON object that recursively validates against that message - Extra JSON keys not in the schema make the JSON invalid. ## Task Implement `isValid(schema, rootTypeName, jsonValue) -> bool`. ## Constraints - Up to ~10^4 total fields across all message types. - Message nesting depth is bounded (e.g., ≤ 50). ## Example Schema: - `User { id:int (required), name:string (optional) }` Valid JSON: `{ "id": 1 }` Invalid JSON: `{ "name": "a" }` (missing required `id`) Invalid JSON: `{ "id": 1, "age": 10 }` (unknown field `age`)

Quick Answer: This question evaluates schema validation and data-typing skills, including understanding of JSON primitive types, recursive message structures, and conformance to a protobuf-like schema with required and optional fields.

Related Interview Questions

  • Merge Overlapping Collinear Segments - Applied (hard)
  • Implement a Fixed-Capacity Deque - Applied (medium)
  • Implement Nested Transactional Key-Value Store - Applied (hard)
  • Merge overlapping 2D line segments - Applied (medium)
  • Find intersection of two line segments - Applied (easy)
Applied logo
Applied
Jan 22, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
1
0
Loading...

You are given a simplified protobuf-like schema definition and a JSON value. Determine whether the JSON conforms to the schema.

Schema model

  • A schema contains named message types .
  • Each message type contains fields . Each field has:
    • name (string)
    • type (one of: int , float , bool , string , or another message type name)
    • optional (boolean)

Assume:

  • The JSON root is an object corresponding to a specified root message type.
  • A required field ( optional = false ) must be present.
  • An optional field may be missing.
  • If a field is present, its JSON value must match the expected type:
    • int : JSON number with no fractional part
    • float : JSON number (integer values are allowed)
    • bool : JSON boolean
    • string : JSON string
    • message type: JSON object that recursively validates against that message
  • Extra JSON keys not in the schema make the JSON invalid.

Task

Implement isValid(schema, rootTypeName, jsonValue) -> bool.

Constraints

  • Up to ~10^4 total fields across all message types.
  • Message nesting depth is bounded (e.g., ≤ 50).

Example

Schema:

  • User { id:int (required), name:string (optional) }

Valid JSON: { "id": 1 } Invalid JSON: { "name": "a" } (missing required id) Invalid JSON: { "id": 1, "age": 10 } (unknown field age)

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Applied•More Software Engineer•Applied Software Engineer•Applied Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.