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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Flatten Nested JSON to Table
00:00
5 left

Flatten Nested JSON to Table

HardPython

Problem

LSEG Workspace event payloads can contain nested objects and arrays that are difficult to process directly. Write a function that converts one nested JSON object into a list of flat row objects.

Formal Specification

Implement flatten_json(obj):

  • Input: obj, a JSON object represented as a dictionary. Values may be dictionaries, lists, strings, numbers, booleans, or None.
  • Output: a list of dictionaries, where every leaf value is stored under a dot-separated key path.
  • Nested dictionary keys must be joined with .. For example, {"quote": {"bid": 101}} becomes { "quote.bid": 101 }.
  • A list expands into multiple output rows. Each element contributes values at the same path.
  • If multiple lists occur in one object, produce the Cartesian product of their elements and repeat scalar values in every resulting row.
  • An empty list contributes one row with value None, preserving the path.
  • Input object keys do not contain .. Preserve input order when producing rows.

Constraints

  • 1 <= number of input keys <= 100
  • Maximum nesting depth is 20
  • Total number of JSON nodes is at most 10^4
  • Array expansion may produce at most 10^4 output rows
  • Object keys are non-empty strings and contain no .

Function Signature

def flatten_json(obj):
Interviewer

Your question is Flatten Nested JSON to Table. 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.