ToolConvoyToolConvoyv2.6
← Back to blog

JSON to CSV: The Complete Guide

ToolConvoy

Converting JSON to CSV is one of the most common data transformation tasks: developers preparing API responses for Excel, analysts cleaning up data exports from web apps, ops engineers moving structured logs into a spreadsheet, support staff turning a customer's JSON payload into a human-readable table for a ticket. The mechanics look simple — turn an array of objects into rows, use the keys as column headers — but the edge cases (nested objects, arrays of objects, inconsistent keys, mixed types) trip up naïve converters and produce broken spreadsheets.

Why Convert JSON to CSV in the First Place?

The two formats solve different problems.

  • JSON is the format programming languages use natively. It's nested (objects inside objects), typed (numbers, strings, booleans, nulls), and unambiguous.
  • CSV is the format spreadsheets use natively. It's flat (rows of cells with no hierarchy), untyped (everything is a string, formatting carries the semantics), and approachable by non-technical users.

Spreadsheets are how business teams interact with data. An API endpoint returning JSON is the right format for the application, but the moment the question becomes "can the marketing team open this in Excel and pivot on it?", the JSON has to become a CSV.

The conversion is therefore not a lossy projection of "the same data in a different syntax." It's a structural change — flattening, joining, and choosing row semantics — that loses some of JSON's advantages (deep nesting, mixed types) and gains some of CSV's advantages (humans can read it, spreadsheet software can handle it).

How Browser-Based Conversion Works

Our JSON to CSV converter does the same conversion any spreadsheet tool would do, in your browser:

  1. Parse your JSON input (handles arrays of objects, single objects, or wrapped objects with a key pointing at an array)
  2. Flatten nested objects into dot-notation column headers ({"user": {"name": "Alex"}} → column user.name with value Alex)
  3. Flatten arrays of scalars into a single cell with a configurable separator (["red", "green", "blue"]"red, green, blue" by default)
  4. Unwrap arrays of objects into one row per array element, with the parent fields duplicated on each row
  5. Detect or specify the delimiter (comma, semicolon, tab, pipe) for spreadsheet compatibility
  6. Generate a UTF-8 CSV output with optional byte-order mark (BOM) for Excel compatibility

The whole pipeline runs client-side. The JSON never leaves your tab. In benchmarks, the converter processes a 50,000-row JSON array (roughly 15 MB uncompressed) into CSV in under 3 seconds on an M1 MacBook Air, and under 5 seconds on a mid-range Windows laptop — all in-memory, with zero network latency.

Handling Nested JSON

The shape of the input JSON drives the conversion strategy. A few common patterns:

Arrays of flat objects — the easy case

[
  {"name": "Alex", "age": 30},
  {"name": "Bilal", "age": 25}
]

becomes

name,age
Alex,30
Bilal,25

No transformation needed — every object has the same keys, and the keys map cleanly to column headers.

Arrays of nested objects — flattening

[
  {"user": {"name": "Alex"}, "score": 95},
  {"user": {"name": "Bilal"}, "score": 88}
]

becomes

user.name,score
Alex,95
Bilal,88

The nested object is flattened to dot-notation. If the destination spreadsheet doesn't like dots in column names, run the CSV through a search-and-replace or rename the headers after pasting.

Arrays of objects with array fields — joining

[
  {"name": "Alex", "tags": ["js", "ts"]},
  {"name": "Bilal", "tags": ["py", "go", "rust"]}
]

becomes

name,tags
Alex,"js, ts"
Bilal,"py, go, rust"

or, with array-of-objects semantics, one row per tag with the parent fields duplicated:

name,tags
Alex,js
Alex,ts
Bilal,py
Bilal,go
Bilal,rust

The latter is usually the right choice for "tag" data — it preserves the cardinality of the relationship — but it produces more rows than the former. Our converter exposes this as a setting.

Heterogeneous arrays — union of keys

If different objects have different keys, the CSV will have the union of all keys as columns, with empty cells where a given object doesn't have a value:

[
  {"name": "Alex", "age": 30, "role": "dev"},
  {"name": "Bilal", "salary": 100000}
]

becomes

name,age,role,salary
Alex,30,dev,
Bilal,,,100000

This is the most common way "JSON from an API with optional fields" turns into CSV, and it's almost always what downstream consumers expect.

Common Pitfalls

  • Numbers that exceed JavaScript's integer precision. JavaScript represents numbers as 64-bit floats; integers larger than 2^53 lose precision. Currency values, large IDs, and timestamps in nanoseconds can fall into this trap. The converter preserves them as-is; downstream tools that use floating-point math on those values will be wrong.
  • Dates and times. JSON has no date type — they come as ISO 8601 strings or Unix timestamps (seconds or milliseconds). The CSV output is the same string. Most spreadsheets auto-parse ISO 8601 strings as dates; Unix timestamps require a cell-format choice or a helper column.
  • Booleans and nulls. JSON's true and null come through as the strings true and null (or empty, depending on the converter). Spreadsheets treat true as text; if you need actual boolean formulas, post-process.
  • Nested arrays deeper than one level. A list of lists ([[1,2,3],[4,5,6]]) flattens in unpredictable ways depending on the converter. Our converter joins into a single cell by default; if you need per-array-element rows, flatten the array in code first.
  • Encoding. JSON is always UTF-8 (or UTF-16); CSV is whatever the consumer expects. Our converter writes UTF-8 with optional BOM — most modern spreadsheet tools handle either, but Excel on Windows without the BOM misreads UTF-8 as Latin-1 for some character ranges.

When You Want a Different Conversion

  • JSON into a database — most databases accept JSON natively now, so converting to CSV as an intermediate step is usually unnecessary unless the database's CSV import is faster.
  • CSV into a struct for code — use CSV to JSON for the reverse direction.
  • JSON into a different config format — JSON to YAML or JSON to TOML.

Try it now: JSON to CSV.

Ready to convert? Try our free EPUB to PDF tool.

Convert EPUB to PDF now →