Cadmeo

JSON to CSV Converter

An array of objects, or a single object. Nested values are flattened into dotted column names.

2
Rows
4
Columns
CSV
name,role.title,role.level,remote
Amara,Engineer,3,
Caleb,Designer,,true

The JSON to CSV converter flattens nested objects into dotted column names and takes the union of keys across every record, so a field present in only some objects still gets a column. Those two behaviours are the whole difficulty of this conversion: JSON is a tree and CSV is a grid, and something has to give.

How it works

  • Nested objects flatten to dotted keys: { role: { title: "Engineer" } } becomes a column named role.title.
  • Arrays flatten to indexed keys: tags: ["a","b"] becomes tags.0 and tags.1.
  • Columns are the union of every key across every record, in first-seen order, so a record missing a field gets an empty cell rather than shifting its columns.
  • Empty objects and empty arrays produce a single empty cell rather than disappearing.

Values containing the delimiter, a quote or a newline are wrapped in quotes with internal quotes doubled, per RFC 4180, the same rules the CSV to JSON converter reads.

Examples

Nested objects and missing keys

JSON

[
  { "name": "Amara", "role": { "title": "Engineer", "level": 3 } },
  { "name": "Caleb", "role": { "title": "Designer" }, "remote": true }
]

Result

name,role.title,role.level,remote
Amara,Engineer,3,
Caleb,Designer,,true

Four columns from the union of both records. Amara has no remote field and Caleb has no role.level, so each gets an empty cell in that column rather than a shifted row.

A value containing the delimiter

JSON

[{ "role": "Designer, Senior" }]

Result

role
"Designer, Senior"

The comma forces quoting. Without it the single value would read as two columns when the file is parsed back.

Frequently asked questions

How are nested objects handled?

They are flattened into dotted column names. Role.title, role.level. CSV has no way to express a tree, so the alternatives are flattening, serialising the nested object into one cell as a JSON string, or refusing. Flattening produces the most usable spreadsheet.

What happens when records have different fields?

The header is the union of every key seen across all records, in the order first encountered. A record missing a field gets an empty cell. This is what stops rows misaligning, which is the usual failure when a converter takes its columns from the first record only.

How are arrays converted?

By index, so tags: ["red","blue"] becomes columns tags.0 and tags.1. That works well for fixed-length arrays and badly for variable-length ones, a record with fifty tags creates fifty columns. Consider reshaping the data first if your arrays vary a lot in length.

Which delimiter should I choose?

Comma unless your data contains many commas, in which case tab produces a cleaner file with less quoting. Semicolon is the convention in locales where the comma is the decimal separator, and Excel in those locales expects it.