How to Convert JSON to CSV (and CSV to JSON)
Convert JSON to CSV and back without losing data. We fed awkward values to pandas, Papa Parse and Python's csv module: ZIP codes lost their leading zeros and a 16-digit order ID came back with the wrong last digit.
JSON to CSV
A flat array of objects maps directly: each object is a row, each key a column.
[{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}]
name,age
Alice,30
Bob,25
Nested data has to be flattened. The usual convention, and the one the JSON-CSV Converter uses, is dot notation: {"user": {"name": "Alice"}} becomes a user.name column, and array items become tags.0, tags.1. Keys missing from some objects become empty cells, which is why a JSON โ CSV โ JSON round trip brings absent keys back as empty strings: CSV cannot tell "missing" from "empty".
CSV to JSON
Each row becomes an object keyed by the header row. CSV has no types, so everything arrives as text; the risk is in what a converter does to that text when it guesses types.
Measured: What Readers Do to Awkward Values
We fed one small CSV with a ZIP code, phone numbers, long order IDs, a price, booleans and dates to three common readers (October 13, 2026; file and script in our test folder):
| Value in the CSV | pandas 3.0.2 read_csv, defaults | Papa Parse 5.4.1, dynamicTyping | Python csv module |
|---|---|---|---|
ZIP 02134 | 2134 | 2134 | "02134" |
Order ID 9007199254740993 | 9007199254740992.0 (wrong last digit) | "9007199254740993" (kept as text) | "9007199254740993" |
Order ID 12345678901234567890 | 1.2345678901234567e+19 | kept as text | kept as text |
1e3 | 1000.0 | 1000 | "1e3" |
Price 1.10 | 1.1 | 1.1 | "1.10" |
TRUE | "TRUE" | true | "TRUE" |
Every reader handled the quoted comma, the doubled quotes and the line break inside a quoted field correctly; the damage is all in type guessing. ZIP codes and phone numbers lose leading zeros, and integers above 253 (9,007,199,254,740,992) cannot survive as JavaScript or float64 numbers: even JSON.parse("9007199254740993") returns 9007199254740992. Treat identifiers, codes and anything with a leading zero as text, and only convert columns you know are numeric.
The JSON-CSV Converter converts a value to a number only when it is a canonical JSON number within 253, so 02134, 0x1A and 20-digit IDs stay text, and true/false conversion is optional. We checked it against Python's csv module on 12 awkward files when we rebuilt it.
Quoting Rules (RFC 4180)
- A field containing a comma, a double quote or a line break must be enclosed in double quotes:
"New York, NY". - A double quote inside a quoted field is written twice:
"She said ""hi""". - Line breaks are CRLF in the RFC; most readers accept LF too.
- Not every "CSV" uses commas. Spreadsheets in many European locales export semicolons, because the comma is their decimal separator; pick the delimiter on import (the converter can detect it).
In Code
JavaScript: Papa.parse(text, { header: true }) and Papa.unparse(rows); leave dynamicTyping off, or limit it to known numeric columns with its per-column function form. Python: csv.DictReader keeps everything as text; with pandas pass dtype=str (or a per-column mapping) to read_csv to stop it rewriting IDs.