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
Parse and Clean Nested JSON
00:00
5 left

Parse and Clean Nested JSON

HardPython

Problem

TetraScience assay payloads can contain measurements nested under experiments, samples, panels, and other JSON containers. Write a function that recursively extracts valid measurement objects and returns a clean, flat list while preserving the nearest assay, experiment, and sample identifiers.

A measurement object is any JSON object containing both analyte and value. Normalize each valid measurement as follows:

  1. Trim whitespace from string fields.
  2. Convert analyte to lowercase.
  3. Convert numeric values and numeric strings to Python float values.
  4. Convert non-empty unit strings to uppercase. Use None when unit is missing or blank.
  5. Skip measurements with a missing or blank analyte, a missing value, or a value that cannot be converted to a finite number.
  6. Include the nearest inherited assay_id, experiment_id, and sample_id. Use None when an identifier is unavailable.

Formal Specification

Input payload is a JSON-compatible Python dictionary containing nested dictionaries, lists, strings, numbers, booleans, or None. Return a list of dictionaries with exactly these keys: assay_id, experiment_id, sample_id, analyte, value, and unit. Preserve depth-first traversal order. Identifiers found on a nested object override inherited identifiers for that object's descendants.

Constraints

  • 1 <= number of JSON nodes <= 10^5
  • Nesting depth is at most 500
  • Each measurement contains at most one analyte and value field
  • Values are JSON-compatible primitives
  • Output preserves depth-first traversal order

Function Signature

def clean_assay_results(payload):
Interviewer

Your question is Parse and Clean Nested JSON. 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.