Your data is nested, and your spreadsheet is not. A JSON export describes each person with an address object inside the record, with its own fields inside that. A CSV file has one flat grid of rows and columns, with nowhere for an object inside an object to live. So before JSON can become a spreadsheet, something has to flatten it.
Most guides tell you to run a flattening step first, with a script or a separate utility. With the free JSON to CSV Converter on Ovatly, that advice is out of date: the converter flattens nested objects itself as part of the conversion. This guide explains what flattening means and where it stops.
Contents
- Quick answer
- What flattening actually means
- Dot-style columns: how nested objects become flat
- The column union rule
- What does not flatten: arrays
- When deep nesting makes a table too wide
- How to convert nested JSON to CSV, step by step
- Worked example: two people, one nested address
- Limitations and honest tradeoffs
- Common mistakes
- FAQs
- Conclusion
- References
Quick answer
You do not need to flatten nested JSON before converting it. Open the JSON to CSV Converter, paste your JSON or upload a .json file, and the converter flattens nested objects into dot-style columns as it converts: an address object inside a record becomes a column named address.city, address.country and so on. It shows you the record and column counts, and you download the result as converted.csv, all fully locally in your browser.
What flattening actually means
Flattening is the process of taking a structure with levels and pressing it into a single level. A nested record looks like this: a name at the top level, and an address one level down, holding a city and a country. A flat table has no levels, so each path through the structure has to become its own column name. The path is written with dots: the city inside the address becomes the column address.city.
That one idea is the entire technique. Every leaf value gets a column named by the path that reaches it, and every record becomes one row under those columns. You can predict the shape of any table before you convert.
Dot-style columns: how nested objects become flat
When the converter meets an object inside an object, it prefixes the inner keys with the outer key and a dot. Nesting can go deeper than one level, and the path simply grows: a field three levels down gets a three-part dotted name.
Two properties of this deserve attention. First, the original key names survive inside the column names, so the table stays readable and traceable. Second, values are written as they appear, never reformatted: a number stays the number it was, text stays the exact text. Flattening rearranges structure; it does not edit data.
The column union rule
Real exports are untidy: one record has a field the others lack. The converter builds its columns as the union of all keys in all records, in the order they first appear. If the second record introduces an age field that the first record does not have, age becomes a column for the whole table, and the first record simply gets an empty cell in it.
This is the behaviour you want, because the alternative is silent data loss. Nothing is dropped for being unusual. The price is that an inconsistent export produces a wide table with many empty cells.
What does not flatten: arrays
Objects flatten. Arrays do not, at least not into columns, and the difference matters.
A simple array, a list of plain values like tags, is joined into a single cell with a semicolon separator. An array of objects is different again: it is written as JSON text inside the cell, unchanged, rather than as a set of columns.
The reason is arithmetic. An array can hold a different number of items in every record, so there is no fixed set of columns it could flatten into. If the array contents are the part you actually need as rows, that is a different conversion.
When deep nesting makes a table too wide
Flattening always works mechanically; the result is not always useful. Each unique path becomes a column, so deeply nested data produces a table dozens of columns wide, most of them empty for most rows. Such a spreadsheet is technically correct and practically unreadable.
Treat width as a signal. If the flattened table is too wide to scan, the data is probably several tables wearing one coat: a list of orders, each with its own list of items, wants to be two tables, not one. And if the nested detail is not what you are analysing, a column of JSON text in a cell may be exactly enough.
How to convert nested JSON to CSV, step by step
- Open the JSON to CSV Converter and paste your JSON, or upload a .json file.
- Check the record count and column count the tool shows: they tell you at once how wide your table is.
- Download converted.csv and open it in your spreadsheet. Scan the column headers: dotted names like address.city show you which parts of the JSON were nested.
- Look at a few rows for empty cells and for cells holding JSON text. Both are expected: empties where a record lacked a key, JSON text where a record held an array of objects.
Worked example: two people, one nested address
Take the converter's own example shape: two people, each with a nested address, and only one of them with an age.
[
{ "name": "Ana", "address": { "city": "Lisbon" } },
{ "name": "Ben", "address": { "city": "Porto" }, "age": 31 }
]
The converter flattens the address object into a dot-style column, takes the union of all keys (name, address.city, age), and leaves Ana's age cell empty because her record has no age:
name,address.city,age
Ana,Lisbon,
Ben,Porto,31
Two records, three columns, nothing lost and nothing invented. The output is comma-delimited CSV with standard minimal quoting, so any spreadsheet opens it.
Limitations and honest tradeoffs
There is no separate flattening step in this workflow, and no separate flattening control either: the converter flattens as it converts, and you cannot ask it to keep one chosen object unflattened while flattening the rest. Arrays of objects stay as JSON text in a cell, which preserves them but does not analyse them. The converter also refuses some inputs outright: a plain scalar, or a mixed array with no clear columns, is rejected with an explanation. And because values are written as they appear, flattening will not tidy your data: inconsistent spellings and mixed formats arrive in the table exactly as they left the JSON.
Common mistakes
- Flattening by hand first. Editing nested JSON into a flat shape by hand wastes effort and risks changing values. The converter does this step itself.
- Expecting arrays of objects to become columns. They become JSON text in one cell. If those items need their own rows, that is a different conversion.
- Panicking at empty cells. An empty cell usually means that record never had the key. The union rule keeps the column and leaves the gap honest.
- Assuming a wide table means an error. Many columns usually mean deeply nested or inconsistent source data, faithfully reported.
- Feeding the converter a single value. A lone number or string has no columns. The input has to be records: an array of objects, one object, or an array of arrays.
FAQs
Do I need to flatten my JSON before converting it to CSV? No. The JSON to CSV Converter flattens nested objects itself during conversion, turning them into dot-style columns such as address.city. There is no separate flattening step to run first.
What happens when one record has a key the others do not? The columns are the union of all keys across all records, in the order they first appear. A record that is missing a key gets an empty cell in that column.
What happens to arrays inside my JSON? Simple arrays are joined into a single cell with a semicolon separator. Arrays of objects are not flattened into columns; they are written as JSON text in the cell.
Can I convert a single JSON object instead of an array? Yes. A single object converts into a one-row table. The converter also accepts an array of arrays.
Why was my JSON rejected by the converter? The input needs to be records: an array of objects, a single object, or an array of arrays. A plain scalar or a mixed array has no clear columns to build, so the converter refuses it and explains why.
Conclusion
Flattening sounds like a job, and with this converter it is already done for you: nested objects become dot-style columns, every key gets its column, and the gaps stay visible instead of being silently filled. Knowing the rules (objects flatten, arrays join or stay as text, width reveals shape) lets you predict the table before you convert. If you are still getting comfortable with the shapes inside a JSON file, our companion guide to JSON data types explains the six types every value belongs to. For more guides in this series, see our Data and JSON Tools guides.
References
- RFC 4180, the common format for CSV files: https://www.rfc-editor.org/rfc/rfc4180
- MDN Web Docs, on working with JSON data: https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Scripting/JSON