Converting JSON to CSV Without Losing Data
JSON is how APIs return data; CSV is what spreadsheets, BI tools and many import screens expect. The two do not map perfectly: JSON can nest and vary its shape, while CSV is a flat grid. Knowing how a converter bridges that gap helps you avoid broken columns and silently lost values.
Input shape
The ideal input is an array of objects, where each object becomes one row. A single object is treated as a one-row table. If your API wraps the list (for example { "data": [...] }), paste only the inner array.
Escaping rules
CSV follows RFC 4180: any value containing a comma, double quote or line break is wrapped in double quotes, and quotes inside it are doubled. Skipping this step is the main reason hand-made CSV files shift columns.
name,quote
"Linus, T.","He said ""hi"""Types are lost in CSV
CSV stores everything as text. When converting back to JSON, numbers and booleans come back as strings. If you need real types, convert them in your code after parsing, or keep JSON as the source of truth.
Doing it in code
For large files or automation, the command-line tool jq can produce CSV directly:
jq -r '(.[0] | keys_unsorted) as $k | $k, (.[] | [.[$k[]]]) | @csv' data.json > data.csv