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 API Response Data Points
00:00
5 left

Validate API Response Data Points

MediumPython

Problem

In a Capgemini API testing workflow, an automated check must verify selected data points in a JSON response. Implement a function that confirms every requested path exists and contains the expected value, including values nested inside dictionaries and lists.

Formal Specification

Write validate_response(response, checks).

  • response is a JSON-compatible Python object containing dictionaries, lists, strings, numbers, booleans, or None.
  • checks is a list of dictionaries. Each dictionary contains:
    • path: a non-empty list of string dictionary keys or integer list indexes.
    • expected: the required value at that path.
  • Return True only when every path exists and its value equals expected with the same Python type. For example, True must not match 1.
  • Return False if a path is missing, an index is invalid, an intermediate value has the wrong container type, or any value does not match.
  • An empty checks list is valid and should return True.

Constraints

  • 0 <= len(checks) <= 10^4
  • 1 <= len(path) <= 50 for every check
  • Each path segment is a string key or a non-negative integer list index
  • The response contains at most 10^5 total JSON nodes
  • Values must match both by type and by value

Function Signature

def validate_response(response, checks):
Interviewer

Your question is Validate API Response Data Points. 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.