How to Flatten Nested JSON for CSV Export
CSV is a flat grid of rows and columns. JSON can nest objects and arrays arbitrarily deep. Bridging that gap is the hard part of JSON to CSV conversion.
The problem
{
"name": "Alice",
"address": { "city": "Paris", "zip": "75001" }
}
A flat CSV can't hold address as a cell. You have to decide how to represent it.
Strategy 1: dot-notation columns
Flatten nested keys into compound column names:
name,address.city,address.zip
Alice,Paris,75001
This keeps every value in its own column and is the most spreadsheet-friendly approach.
Strategy 2: serialize the nested value
Store the nested object as a JSON string in one cell:
name,address
Alice,"{""city"":""Paris"",""zip"":""75001""}"
Compact, but the cell is no longer easy to read or sort.
Handling arrays
Arrays are trickier. Options:
- Join simple arrays into one cell:
"red; green; blue". - Explode into multiple rows (one row per array item), repeating the parent fields.
- Index into columns:
tags.0,tags.1.
Pick based on whether you need to filter/sort those values in the spreadsheet.
Tip
Before flattening, make sure the JSON is valid — run it through the config validator. Then convert with the JSON to CSV tool.
Got a config file to check?
Open the config toolkit →