Data conversion

How to convert nested JSON to CSV

CSV stores rows and columns, while JSON can contain nested objects, arrays, and mixed structures. A reliable conversion requires clear rules for selecting records, naming columns, and representing nested values.

10 min read Reviewed July 19, 2026 Professional reference

Document summary

Choose one array of similar records, flatten object paths into stable column names, handle nested arrays deliberately, and inspect the output before importing it into a spreadsheet or database.

Key takeaways

  • The cleanest CSV source is an array of records with a reasonably consistent shape.
  • Flattened column names should preserve the original path and avoid ambiguous collisions.
  • Arrays of objects often need a second table instead of being forced into one cell.
01

Understand the difference between JSON and CSV

JSON represents hierarchical data. CSV represents a flat table where every row shares a set of columns.

The conversion process therefore needs a policy for nested objects, arrays, missing values, and data types.

JSON featureCSV challengeCommon approach
Nested objectNo nested cell structureFlatten the path into columns.
Array of primitivesOne cell cannot hold multiple typed valuesJoin values with a chosen separator.
Array of objectsRepresents a related tableCreate repeated rows or a separate CSV.
Missing propertyRows have different shapesLeave the cell empty or use a defined placeholder.
02

Choose the record array

The best source is an array of similar objects. When the JSON root is an object, identify the property that contains the records you want to export.

Invalid
{
  "page": 1,
  "results": [
    {"id": 1, "name": "Ada"},
    {"id": 2, "name": "Lin"}
  ]
}
Valid
[
  {"id": 1, "name": "Ada"},
  {"id": 2, "name": "Lin"}
]
03

Flatten nested objects with stable paths

Dotted paths make the original hierarchy visible without creating nested CSV cells. For example, profile.city becomes a column name while preserving where the value came from.

Invalid
{
  "id": 1,
  "profile": {
    "name": "Ada",
    "city": "London"
  }
}
Valid
id,profile.name,profile.city
1,Ada,London
04

Handle arrays deliberately

Primitive arrays can often be joined into one cell. Arrays of objects usually represent one-to-many relationships and need a more careful choice.

  • Join small primitive arrays with a delimiter such as a vertical bar.
  • Repeat the parent row for each child record when that supports the destination.
  • Create a separate child table and keep a parent identifier.
  • Store compact JSON in one cell only when the destination can parse it later.
05

Preserve values and data types

CSV has no universal type system. Spreadsheet software may reinterpret identifiers, dates, leading zeros, and long numbers.

ValueRiskSafer export decision
00123Leading zeros may disappearTreat as text when it is an identifier.
2026-07-19May be reformatted by localeUse an explicit ISO date and document the column.
1234567890123456789Spreadsheet precision lossExport as text when exact digits matter.
true or falseMay become inconsistent labelsUse one documented representation.
06

Build a complete and predictable header set

Records may contain optional fields. Scan the relevant records to collect the full column set, then output the same columns in the same order for every row.

07

Escape commas, quotes, and line breaks correctly

A CSV field containing a delimiter, quotation mark, or line break must be quoted. Quotation marks inside the field are represented by doubling them.

Invalid
1,Ada,Hello, world
Valid
1,Ada,"Hello, world"
08

Protect spreadsheet exports from formula injection

Spreadsheet applications may treat cells beginning with characters such as equals, plus, minus, or at sign as formulas. Untrusted values should be escaped or imported with safe text handling.

09

Review the generated CSV before import

Preview the header row, several records, missing values, and quoted fields before downloading. Test the file in the actual destination when data types or nested relationships matter.

  1. 1

    Confirm the selected record array.

  2. 2

    Review flattened column names.

  3. 3

    Inspect array handling.

  4. 4

    Check identifiers, dates, and large numbers.

  5. 5

    Open a sample in the destination application.

Jump to tool

Convert nested JSON into a downloadable CSV

Open tool