Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Ingest Nested JSON to Delta

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Ingest Nested JSON to Delta. Start with the requirements on the right.

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.

Problem

Write a clean, modular Python function to parse and ingest highly nested JSON logs into a partitioned Delta table. Implement the transformation layer without requiring Spark APIs: parse each JSON document, flatten nested objects using dotted keys, preserve arrays as values, and group records by a nested partition field. The function receives JSON strings and returns a dictionary mapping partition values to normalized records ready for Delta ingestion.

Signature: def parse_and_partition_logs(logs, partition_field):

Input/output: logs is a list of JSON strings; partition_field is a dotted path; return {partition_value: [record, ...]}. Raise ValueError for invalid JSON, missing partition fields, or non-scalar partition values.

Constraints

  • 0 <= len(logs) <= 10^4
  • Each log is a valid JSON string representing an object unless testing error handling
  • Nested object depth is at most 100
  • partition_field contains one or more non-empty dot-separated keys
  • Partition values must be scalar JSON values
  • Array values are preserved as leaf values

Function Signature

def parse_and_partition_logs(logs, partition_field):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output