Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Transform JSON Logs to Tables

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

Your question is Transform JSON Logs to Tables. 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 Python function to parse and transform complex JSON logs into a structured tabular format.

Implement parse_logs(logs). Each input element is a JSON object representing one log record. Flatten nested objects using dot-separated keys, preserve scalar values, and encode arrays as compact JSON strings. Return a list of row dictionaries with the union of all flattened columns, sorted lexicographically. Fill missing columns with None.

Input: a list of JSON-compatible dictionaries. Output: a list of dictionaries. The input order must be preserved.

Constraints

  • 0 <= len(logs) <= 1000
  • Each log is a JSON-compatible dictionary
  • Dictionary nesting depth is at most 50
  • Keys are strings
  • Arrays may contain any JSON-compatible values
  • Output rows preserve the input order

Function Signature

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