Skip to content

Convert JSON to CSV without silently losing fields

Handle inconsistent JSON fields, commas, quotes, nested values and spreadsheet formulas when exporting API records as CSV.

By DevToolPlace · Published October 5, 2026 · 2 min read

Define what one row represents

CSV is a table; JSON can contain deeply nested objects and arrays. Start with an array of records and decide which fields become columns. If each record contains several orders, decide whether to emit one row per person, one per order or separate files. That decision changes the meaning of the export and cannot be inferred safely by a generic converter.

Collect fields from every record

Using only the first record for column names silently drops fields that appear later. This example requires id, name and email columns even though email is missing from the first record. Leave missing cells empty or choose an explicit missing-value policy. An empty cell cannot always distinguish a missing key from null or an empty string.

[
  {"id": 1, "name": "Ada"},
  {"id": 2, "name": "Lin", "email": "lin@example.com"}
]

CSV:
id,name,email
1,Ada,
2,Lin,lin@example.com

Quote cells using CSV rules

A comma, newline or double quote inside a value needs careful handling. Quote the whole field and double any internal quote. Do the same for headers. Do not join raw strings with commas. The following field contains both a comma and quotation marks.

JSON value: Ada, "A"
CSV field: "Ada, ""A"""

Choose an explicit nested-data policy

For an address object, either flatten selected keys into address.city and address.country or store the object as JSON within a quoted cell. DevToolPlace serializes nested values as JSON text. This preserves a readable representation but does not create relational columns. For large or sensitive exports, implement the policy in your application and stream the file instead of using an online utility.

Review spreadsheet interpretation

Spreadsheet software can interpret values beginning with =, +, - or @ as formulas. Quoting CSV syntax alone does not prevent that behavior. For untrusted values, use an import mode that treats cells as text or an export format with explicit cell types. Preserve a raw export separately if exact bytes matter. Also inspect leading zeros, long identifiers, Unicode characters and line endings after importing.

Reference documentation

Try the related tools with sample data

Found an error or a missing edge case? Send a reproducible example.