Data converters · 5 min read
JSON to CSV: flattening nested data without losing meaning
CSV is still the format that opens in anything: spreadsheets, BI tools, finance systems, a reviewer’s laptop. Converting JSON to CSV is mostly a question of what to do with the nested parts, because a table has one row per record and columns fixed in advance, while JSON happily nests as deep as it likes.
Updated
The column problem
Two rules make a JSON to CSV conversion predictable. First, the columns are the union of all keys across all records — a key that appears in only one object still gets a column, empty elsewhere. Second, every row must emit values in the same order. Getting either wrong produces a file that opens fine and is silently misaligned from the first row where a key was absent.
Flattening nested objects
The conventional technique is dot notation: `address` containing `city` and `postcode` becomes `address.city` and `address.postcode`. That keeps every value visible and queryable in the spreadsheet, at the cost of longer headers. Deeply nested structures can produce unwieldy names, so flatten one level where you control the data and let the tool flatten fully when you are exploring.
{"id": 7, "customer": {"name": "Ada", "plan": "pro"}}
→ id,customer.name,customer.plan
7,Ada,pro
Arrays: the part that flattens badly
An array of scalars can be joined into one cell with a separator, which is fine for tags and acceptable for short lists. An array of objects — order line items, for example — does not belong in a single cell: join it, and you cannot sum the quantities; index it into `items.0.sku`, `items.1.sku`, and the columns depend on how many items each order happened to have. When you hit that case, the data wants two CSV files, one per table, linked by a key.
If a cell contains a comma, quote or newline, it must be quoted and internal quotes doubled. Generated output handles this — hand-edited CSV usually does not, which is why imports fail intermittently on rows containing addresses.
Making the file behave in Excel
Excel assumes the system encoding unless told otherwise, so accented characters can corrupt. Emitting UTF-8 with a byte-order mark avoids that; without it, the same file that looks perfect in Numbers or Sheets shows mojibake in Excel. Long numeric identifiers — card numbers, large SKUs — are also worth quoting so Excel does not convert them to scientific notation.
When CSV is the wrong output
If the consumer is a program, CSV throws away type information and nesting for no benefit — JSON Lines or a database load is better. CSV is for humans with spreadsheets: reports, exports, reconciliation. Choosing it deliberately, rather than by habit, is half the work. The YamlBox JSON to CSV converter runs entirely in the browser, so an export containing customer rows never leaves your machine.
JSON to CSV — frequently asked questions
How are nested objects handled when converting JSON to CSV?
They are flattened with dot notation by default — `customer.name` becomes its own column. You can keep values grouped instead, but flattened columns are what makes the file filterable and pivotable in a spreadsheet.
Why do accented characters look wrong in Excel after conversion?
Excel reads the file using the local system encoding unless a byte-order mark says otherwise. Exporting UTF-8 with a BOM keeps names intact; without it the same data renders correctly in Google Sheets and incorrectly in Excel.
Can I convert an array of objects to CSV?
Columns come from the union of keys across all records, so an array of mixed-shape objects still produces a valid table with blanks where a key was missing. Arrays inside those objects are the case that needs splitting into a second file.
Tools mentioned in this post
Keep reading
5 min read
CSV to JSON: from a spreadsheet to structured data
Convert CSV to JSON in the browser — header rows, delimiters, quoting rules and type handling explained, with the spreadsheet exports that break parsers.
6 min read
Excel to JSON: turning workbooks into structured data
Convert Excel to JSON in the browser from XLSX workbooks — headers, date serials, formulas and multiple sheets explained, with nothing uploaded.
5 min read
Markdown tables: generate them instead of counting pipes
Build GitHub-flavoured markdown tables from rows or spreadsheets — alignment, escaping pipes, and when a table is the wrong choice for your README.