Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Validate JSON Against Schema
00:00
5 left

Validate JSON Against Schema

MediumPython

Problem

Netflix Keystone pipelines receive nested JSON payloads. Implement validate_json(data, schema) to determine whether a JSON-compatible value conforms to a supported schema.

Formal Specification

data is a JSON-compatible Python value: None, bool, int, float, str, list, or dict. schema is a dictionary supporting these keywords:

  1. type: one of null, boolean, number, integer, string, array, or object.
  2. enum: an array of permitted values. The data must equal one of them when present.
  3. properties: an object mapping property names to child schemas. These schemas are checked when the properties exist.
  4. required: an array of property names that must exist when the value is an object.
  5. items: a schema applied to every element when the value is an array.

Return True if every applicable rule passes, otherwise return False. Object properties not listed in properties are allowed. A schema without a keyword imposes no restriction at that level.

Constraints

  • The value contains at most 10^4 total nested values
  • Nesting depth is at most 500
  • Supported schema keywords are type, enum, properties, required, and items
  • Object properties not listed in properties are allowed
  • Inputs contain only valid JSON-compatible values

Function Signature

def validate_json(data, schema):
Interviewer

Your question is Validate JSON Against Schema. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.