Data & APIs

JSON to CSV: Convert Data Without Losing Fields — Practical Guide

Convert JSON to CSV by choosing a row structure, flattening nested fields carefully, and checking quoted commas and empty values. Read the steps and example.

Photorealistic editorial photo for How To Convert Json To Csv
Data & APIs · Practical ideas for your next build

JSON and CSV represent data differently. JSON supports nested objects, arrays, and mixed values, while CSV is a rectangular table of rows and columns. Before converting, decide what one row represents and how nested values should become cells. A converter can produce a file quickly, but no single mapping preserves every JSON structure in a plain CSV. Keep the original JSON and inspect the resulting headers, row count, and quoting before importing the file elsewhere.

Choose the array that represents table rows

Many exports contain an array of objects, where each object becomes a row and each key becomes a column. If records are nested, decide whether to flatten them into dotted paths, join selected values, or serialize a nested value as JSON text inside one cell. Arrays may need one row per item or a joined representation. Record that choice so a later import does not silently reinterpret the data.

Preserve CSV quoting and text types

CSV fields containing commas, quote marks, or line breaks need correct quoting. A valid writer wraps the field in quotes and doubles quote characters inside it. Spreadsheets may also reinterpret strings such as postal codes, dates, and long IDs. Keep identifiers as text and check leading zeros after opening the file. Empty, missing, and null JSON values are distinct concepts; decide how each should be represented.

Validate the converted data

Compare the row count with the intended array length and check the first, middle, and last records. Inspect headers for duplicate keys and columns that contain unexpected objects. If you need a round trip back to the same JSON structure, CSV may be too lossy; retain a schema or use NDJSON for records. Avoid opening sensitive data in a shared spreadsheet or cloud account without authorization.

Worked example

EXAMPLE
[{"name":"Ada Lovelace","postal":"00123"},{"name":"Sam Lee","postal":"94105"}]

name,postal
"Ada Lovelace",00123
"Sam Lee",94105

Can every JSON file be converted to CSV losslessly?

No. CSV has no native nesting or data types, so nested structures and null or missing values need an explicit mapping.

Reference and further reading

Read the official documentation ↗