JSON and data guides
JSON to CSV: flatten nested data without losing columns
Define rows and columns before converting nested JSON, and quote commas, quotes and line breaks correctly.
Define one row
A CSV file is a table, while JSON can contain arbitrarily nested objects and arrays. Conversion needs an explicit rule for what becomes a row.
Start with an array of flat records. For nested input, select the record array and flatten only the fields needed by the downstream consumer.
[{"name":"Ada","city":"London"},{"name":"Lin","city":"Shanghai"}]
name,city
Ada,London
Lin,ShanghaiQuote special characters
A field containing commas, quotes or line breaks needs CSV quoting. Inside a quoted field, a quote is represented by two quotes.
Use a CSV parser rather than splitting on commas. Splitting creates extra columns when a value contains a comma, even if the file is valid.
name,note
Ada,"hello, world"
Lin,"said ""yes"""Keep the schema consistent
Collect the required column names across records; a missing field must not shift later cells left. Decide how null and empty strings are represented.
CSV does not carry JSON types. A round trip can turn a number into text or erase the distinction between null, missing and an empty value.
Review before spreadsheet import
Spreadsheet software may reinterpret leading zeros, long IDs and date-like text. Configure those columns as text when their exact spelling matters.
Cells beginning with formula markers can be interpreted as formulas. Use the receiving spreadsheet application’s safe import controls; CSV quoting alone does not neutralize formulas.