How to Convert Nested JSON to CSV: Flatten Objects and Arrays
Flat JSON converts to CSV in one click. Nested JSON is where most converters fail: objects inside objects, arrays of tags, lists of order items. Here is how flattening works, four ways to handle arrays, and how to do it in your browser, in Python or with jq.
Quick answer
CSV is a flat table, so nested JSON has to be flattened: each nested field becomes its own column with a dot-notation name, such as customer.address.city. Paste your JSON into the free JSON to CSV Converter, keep Flatten nested objects on, check the table preview and download the CSV. Arrays need a decision: keep them as text in one cell, join them, split them into numbered columns, or create one row per item.
Why nested JSON doesn't fit in a CSV
JSON is a tree. A value can be a text, a number, an object containing more fields, or an array containing many values. CSV is a grid: every row has the same columns, and every cell holds one plain value. To go from one to the other, every branch of the tree has to become a column, and anything that repeats has to be squeezed into a cell or spread across rows.
Take this typical API response:
[
{
"id": 1001,
"customer": { "name": "Ana Silva", "address": { "city": "Lisbon", "country": "PT" } },
"tags": ["vip", "newsletter"],
"total": 89.5
},
{
"id": 1002,
"customer": { "name": "Omar Haddad", "address": { "city": "Casablanca", "country": "MA" } },
"tags": [],
"total": 42
}
]
A naive converter gives you a customer column full of [object Object]. That is the problem flattening solves.
Flattening objects: dot-notation columns
Flattening walks down every nested object and joins the keys with a dot. The example above becomes:
| id | customer.name | customer.address.city | customer.address.country | tags | total |
|---|---|---|---|---|---|
| 1001 | Ana Silva | Lisbon | PT | ["vip","newsletter"] | 89.5 |
| 1002 | Omar Haddad | Casablanca | MA | [] | 42 |
Two details matter in real data:
- Missing fields. If some records have a field and others don't, a good converter collects the columns from every record, not just the first, and leaves the cell empty where a value is missing.
- Column order. Keeping columns in the order they first appear makes the file far easier to read than alphabetical order.
Four ways to handle arrays
Objects have one obvious answer. Arrays don't, because a cell can hold only one value. Pick the strategy that matches what you will do with the spreadsheet.
| Strategy | Result for tags | Best when |
|---|---|---|
| Keep as JSON text | ["vip","newsletter"] | You need a lossless file you can convert back later. |
| Join the values | vip; newsletter | People will read or filter the column in Excel. |
| Numbered columns | tags.0 = vip, tags.1 = newsletter | Arrays are short and have a fixed meaning by position. |
| One row per item | Two rows for order 1001, one per tag | Each item matters on its own, such as order lines you want to sum. |
The first strategy is the safe default, and it is what our converter does: nothing is lost, and the array stays valid JSON inside its cell. For the "one row per item" layout, use the Python method below.
Method 1: in your browser, step by step
- Open the free JSON to CSV Converter and make sure JSON → CSV is selected.
- Paste your JSON or click Open file. If the array is wrapped in an object, such as
{"data": [ ... ]}, it is unwrapped automatically when there is a single array of records. - Keep Flatten nested objects on. Turn it off only if you want each nested object kept as JSON text in one column.
- Choose the delimiter: comma for most tools, semicolon if your Excel uses commas for decimals (common in much of Europe and Latin America).
- Check the table preview for empty or unexpected columns.
- Click Download. Keep Excel-friendly on so accented letters and non-Latin scripts display correctly.
The conversion runs entirely in your browser, which matters when the JSON is a customer or order export.
Try it free: JSON to CSV Converter
Convert JSON to CSV for Excel, or CSV back to JSON, with a table preview. Runs in your browser, no sign-up.
Method 2: Python with pandas
For large files or repeated jobs, pandas.json_normalize does the flattening for you:
import json
import pandas as pd
with open("orders.json", encoding="utf-8") as f:
data = json.load(f)
df = pd.json_normalize(data, sep=".")
df.to_csv("orders.csv", index=False, encoding="utf-8-sig")
The utf-8-sig encoding adds the same invisible marker that makes Excel read accents correctly. To create one row per array item, point record_path at the array and list the parent fields to repeat with meta:
# orders.json has an "items" array inside each order
df = pd.json_normalize(
data,
record_path="items",
meta=["id", ["customer", "name"]],
)
Each item becomes a row, with the order id and customer.name repeated on every line, ready for totals and pivot tables.
Method 3: the command line with jq
If your JSON is an array of flat objects, jq can write CSV directly:
jq -r '(.[0] | keys_unsorted) as $k | $k, (.[] | [.[$k[]]]) | @csv' data.json > data.csv
This takes the column names from the first record, so records with different keys will be misaligned, and @csv refuses nested objects. Flatten first, or use one of the methods above for nested data.
Method 4: Excel Power Query
Excel can import JSON without any conversion: Data → Get Data → From File → From JSON. In the Power Query editor, convert the list to a table, then use the expand button on each column header to pull nested fields into columns, and choose "Expand to New Rows" for arrays. It works well for one-off imports, though the steps take some practice.
Common problems and fixes
- Everything lands in one column in Excel. Your Excel expects semicolons. Download again with the semicolon delimiter.
- Accents and Arabic text look garbled. The file was opened without a UTF-8 marker. Keep the Excel-friendly option on, or use
utf-8-sigin Python. - Leading zeros disappear. Postcodes like 01234 become 1234 when Excel opens a CSV. Import through Data → From Text/CSV and set those columns to Text.
- Hundreds of columns. Deeply nested data or numbered array columns explode the width. Turn flattening off for the deepest parts, or export only the fields you need.
- "Invalid JSON". Trailing commas, single quotes and comments break parsing. Fix them with the JSON Formatter, which shows the exact line and column.
- Numbers lose precision. IDs longer than 15 digits are rounded by Excel. Keep them as text in your source data, or import them as Text.
Going back: CSV to JSON
The same converter works in reverse. Switch to CSV → JSON, paste the CSV, and turn on Detect numbers and booleans so 42 and true become real values instead of text. Note that dot-notation headers stay as flat keys, such as "customer.name", rather than being rebuilt into nested objects.
Frequently asked questions
Can CSV store nested data?
Not directly. CSV has rows and columns only, so nested data must be flattened into columns, stored as JSON text inside a cell, or spread across several rows.
What does "flatten JSON" mean?
It means turning nested objects into a single level of keys, usually by joining parent and child keys with a dot, so {"address": {"city": "Paris"}} becomes {"address.city": "Paris"}.
How do I convert a JSON array of arrays?
If each inner array is a row of values, the first inner array is usually the header. Convert it to an array of objects first, or open it in Python with pd.DataFrame(data[1:], columns=data[0]).
Is it safe to convert JSON online?
Only if the converter runs in your browser. Ours does, so customer exports and API responses are never uploaded.
The bottom line
Converting nested JSON to CSV comes down to two choices: flatten objects into dot-notation columns, and decide how arrays should look. For quick jobs, paste the JSON into the converter and download an Excel-ready file. For recurring or large exports, pandas.json_normalize gives you full control, including one row per array item.
Found something out of date or unclear? Email contact@ultratoolsai.com and we'll fix it.


