83. 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.
Essential
SQL 0/33
Spark 0/20
Snowflake 0/22
Python 0/24
Need more practice in this area? Explore more questions →
Amazon
Revolut
Accenture
Adobe
Google
LinkedIn
Samsung
Datadog
Wix
Dropbox
Meta
OpenAI
Hulu
Uber
X
DoorDash
Anthropic
ActivisionBlizzard
Vercel
Crypto.Com
Zscaler
DeutscheBank
Apple
GoDaddy
GitLab
BMW
PayPal
Snowflake
AMD
Twilio
Atlassian
JPMorgan
NVIDIA
IBM
Databricks
Coinbase
Cisco
Robinhood
Twitter
Microsoft
Palantir
Netflix
VMware
Cloudflare
Stripe
Lyft
Salesforce
GitHub
Bloomberg
Airbnb
Walmart
SAP
HashiCorp
Instacart
Mastercard
Intel
Visa
Tesla