How to Flatten Nested JSON into CSV: Objects, Arrays and Rows

Published 24 November 2026 · 7 min read

A CSV is a flat grid of rows and columns. JSON is a tree: objects hold objects, and arrays hold lists. Turning one into the other means deciding what happens to everything that is not already flat. The answer depends on what you plan to do with the file, so this guide explains the choices and when each one is right.

A small example

Here is one order with a nested customer and a list of items:

{
  "id": 1001,
  "customer": { "name": "Ava", "city": "Austin" },
  "tags": ["new", "gift"],
  "items": [
    { "sku": "A-1", "qty": 2 },
    { "sku": "B-7", "qty": 1 }
  ]
}

The id is already flat. The other three fields are the problem. Each needs a rule.

Nested objects: flatten into columns

The usual rule for an object inside an object is to join the keys with a separator, so customer.name becomes the column customer.name. You get one column for each leaf value:

id,customer.name,customer.city
1001,Ava,Austin

This is almost always what you want, and it loses nothing. If your keys already contain dots, choose a different separator, such as an underscore, so the column names stay unambiguous. The converter lets you set the separator.

Arrays: four ways to handle them

An array has no single right flat form. These are the four common choices:

MethodResult for tagsBest when
Index columnstags.0 = new, tags.1 = giftArrays are short and about the same length
Join in one celltags = new; giftLists of simple values such as tags or roles
Expand into rowsOne row per tag, other fields repeatedArrays of objects you want to count, filter or sum
Keep as JSON text["new","gift"] in one cellYou want to keep the structure and parse it later

Expanding into rows

Expanding turns each array item into its own row and repeats the other fields on every row. Here is what the example order gives with the Arrays setting on Expand into rows:

id,customer.name,customer.city,tags,items.sku,items.qty
1001,Ava,Austin,new,A-1,2
1001,Ava,Austin,new,B-7,1
1001,Ava,Austin,gift,A-1,2
1001,Ava,Austin,gift,B-7,1

Two things to notice. First, the order id repeats on every row, so adding up an order-level number such as a total would count it several times. Sum only item-level columns such as items.qty.

Second, the order has two arrays, tags and items, and the setting applies to every array in the file, so you get every combination: 2 tags times 2 items is 4 rows. That is correct for the rule, but rarely what you want. If you only care about the line items, remove the unwanted array from your JSON first, or convert the file once and keep the file you need. A file with a single array per record expands cleanly: one row per item.

Index columns

This keeps one row per record, which suits a quick look in a spreadsheet. The cost is a ragged table: if one order has 2 items and another has 40, the file gets 40 groups of columns and most cells are empty. Use it for small, regular arrays.

Records with different keys

Real JSON is rarely uniform. One record has a phone field and another does not. A sound converter takes the union of all keys across all records as the header and leaves empty cells where a record lacks a field, so no data is dropped. Check the header row before you rely on the file.

Which settings should you choose?

  • Opening it in Excel or Google Sheets for a person to read: flatten objects, index or join short arrays.
  • Analysing line items or events: flatten objects and expand into rows, with only one array per record.
  • Importing into a database table: expand into rows, with one array per record.
  • You are not sure yet: keep arrays as JSON text, so nothing is lost and you can split the column later.

Pitfalls to check

  • Long IDs and leading zeros. Excel changes them when it opens a CSV. See why Excel changes long numbers, or export to Excel directly.
  • Accented characters or one big column. That is an encoding or delimiter problem, covered in CSV shows garbled characters or one column in Excel.
  • Formulas in text. A cell that begins with =, +, - or @ can be run as a formula when opened in a spreadsheet. If the JSON comes from users, turn on the option that neutralises these cells.
  • Invalid JSON. Fix it first with the JSON Formatter, which shows the exact line and column of the problem.

Try it

Paste your JSON into the JSON to CSV converter. It offers all four array methods and the separator option, shows a preview table before you download, and runs entirely in your browser, so the data is not uploaded. To go the other way, the CSV to JSON converter rebuilds nested JSON from column names such as customer.name.