Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Validate Nested JSON Configurations
00:00
5 left

Validate Nested JSON Configurations

MediumPython

Problem

Given a JSON string representing a hierarchical model configuration, parse it and validate every nested object. Each node must contain a string field name, a string field type, an object field params, and an optional array field children. Return a list of validation errors using dot-paths such as children[1].params.lr. If the JSON is invalid, return [{"path": "$", "message": "invalid json"}].

Constraints

  • 1 <= len(payload) <= 10^5
  • Maximum nesting depth is at most 10^3
  • Each node contains only valid JSON value types
  • children, when present, must be an array of objects

Function Signature

def validate_model_config(payload):
Interviewer

Your question is Validate Nested JSON Configurations. 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
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.