Flatten Nested JSON to CSV with Dot-Notation Columns
Beginner Mode
Start your terminal to use beginner mode.
Scenario
A JSON file contains nested user data that needs to be converted to a flat CSV format for analysis. Nested objects should be flattened using dot-notation column names.
Task
Write a Python script at /home/interview/flatten_json.py that reads /home/interview/users.json, flattens the nested structure using dot-notation for column names, converts arrays to comma-separated strings, and saves the result to /home/interview/flat_data.csv.
Example
Input JSON:
{
"id": 1,
"name": "John Doe",
"contact": {
"email": "[email protected]",
"phone": "555-1234"
},
"hobbies": ["reading", "gaming"]
}
Expected output CSV columns:
id,name,contact.email,contact.phone,hobbies
1,John Doe,[email protected],555-1234,"reading,gaming"
Terminal requires a larger screen
Open this page on a desktop or tablet (≥ 768px) to launch the terminal and practice hands-on.
Linux Terminal Environment
Write and execute your solution in the terminal below.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
Amazon