· CSV.ink Team

How to Convert Nested JSON to CSV Without Losing Fields

A flat JSON array becomes a clean CSV in one step. Nested objects and lists need a rule before you export — here are the patterns that usually work.

JSON likes nesting. CSV does not. If your API returns customers with an address object and a tags array, a naive converter either drops those fields or dumps [object Object] into a cell. You need an explicit flattening rule.

Start from a list of similar objects

CSV is a table: one header row, then rows with the same columns. The happy path is a JSON array where every item is an object with roughly the same keys:

[
  {"id": 1, "name": "Ada", "city": "London"},
  {"id": 2, "name": "Lin", "city": "Taipei"}
]

That maps 1:1 to two data rows. Our JSON to CSV tool is built for this shape.

JSON to CSV converter →

Nested objects → dotted or prefixed columns

When a value is itself an object, lift its keys into columns. address.city and address.zip are easier to filter later than a single JSON blob in one cell.

{
  "id": 1,
  "name": "Ada",
  "address": {"city": "London", "zip": "E1 6AN"}
}

→ id,name,address.city,address.zip
   1,Ada,London,E1 6AN

If two nested objects share a key name, keep the prefix so columns stay unique.

Arrays → join, expand, or drop

Lists do not fit a single cell cleanly. Pick one policy and stick to it for the whole file:

  • Join: tags becomes "a, b, c". Good for reading; bad if a tag itself contains commas.
  • Expand: one row per list item, repeating the parent fields. Good for analysis; row count grows.
  • Drop or keep raw JSON in one column when the list is only needed by another program.

Mixed types and nulls

Export missing keys as empty cells, not the string "null", unless your downstream tool expects the word. Keep IDs and codes as text in the CSV if leading zeros matter — once Excel opens the file, types may change again.

When JSON should stay JSON

Deep trees, recursive children, or documents where every record has a different shape are poor CSV candidates. Convert only the slice you need for a spreadsheet, or use Excel with multiple sheets for different entity types.

JSON to Excel for multi-sheet workbooks →

If you are going the other way — CSV back to JSON — remember that everything comes back as strings unless you cast types yourself.

CSV to JSON →

Ferramentas relacionadas

← Todos os artigos

Mais artigos