JSON to CSV converter
Turn a JSON array into a spreadsheet-ready CSV, or convert CSV back into JSON.
This tool runs in your browser. We never send what you type or paste to a server.
How the conversion works
- Each object in the array becomes a row, and every key that appears in any object becomes a column.
- Nested objects are flattened with dot notation, so
{"user": {"name": "Ana"}}becomes auser.namecolumn. Arrays are written as JSON text. - Values containing commas, quotes or line breaks are wrapped in double quotes, with inner quotes doubled, following RFC 4180.
Opening the CSV in Excel
Download the file and open it, or paste the CSV into the first cell of a sheet and use Data, Text to Columns. If accented characters look wrong in older Excel versions, use Data, From Text/CSV and choose UTF-8.
Example
This array:
[
{"id": 1, "name": "Ana", "city": "Lisbon"},
{"id": 2, "name": "Ben, Jr.", "city": "Leeds"}
]
becomes:
id,name,city
1,Ana,Lisbon
2,"Ben, Jr.",Leeds
The comma in Ben, Jr. is why that field is quoted. Nested objects are flattened into dotted column names such as address.city.
CSV to JSON: how values are typed
CSV has no types: every cell is text. When converting back to JSON, the first row becomes the keys and each cell is typed like this:
- A cell becomes a JSON number only if it survives the trip unchanged, so
42and2.5are numbers but007,1.50and a 20-digit ID stay strings and keep every character. true,falseandnull(exactly, lower case) become booleans and null.- Empty and missing cells become
"", notnull. Cells beyond the last header are dropped. - Dotted headers such as
user.namestay flat keys; they are not rebuilt into nested objects.
So a column can end up mixed: with 1.50 in one row and 2.5 in the next, you get a string and a number. Check the JSON before feeding it to code that expects one type per field.
A worked example with nested data
Input with a nested object, an array and a missing key:
[
{"id": 1, "user": {"name": "Ana", "role": "admin"}, "tags": ["a", "b"]},
{"id": 2, "user": {"name": "Ben"}}
]
Output:
id,user.name,user.role,tags
1,Ana,admin,"[""a"",""b""]"
2,Ben,,
The array is stored as JSON text, so its quotes are doubled inside a quoted cell. Ben has no role and no tags, so those cells are empty. A value of null also gives an empty cell, which means null and a missing key look the same once in CSV.
Gotchas when the CSV reaches a spreadsheet
- Leading zeros: Excel turns
007or a postcode like01234into a number and drops the zeros. Import with Data, From Text/CSV and set that column to Text. - Long numbers: Excel keeps only 15 significant digits, so a 16- to 19-digit ID or card-style number is shown in scientific notation and its last digits become zeros. JavaScript itself rounds integers above 9,007,199,254,740,991, so send long IDs as strings in the JSON.
- Semicolons: in many European locales Excel expects
;between fields because the comma is the decimal separator. Pick Semicolon as the delimiter for those users. - Key clashes: a literal key
"a.b"and a nested{"a": {"b": …}}both flatten to the columna.b, and only one value survives. Rename one of them first.
The same conversion in code
Python has a csv module that quotes for you. Open output files with newline='' or you get blank lines between rows on Windows.
rows = json.loads('[{"id": 1, "name": "Ana", "city": "Lisbon"}, {"id": 2, "name": "Ben, Jr."}]')
cols = list(dict.fromkeys(k for r in rows for k in r)) # every key, first-seen order
out = io.StringIO() # use open('out.csv', 'w', newline='') for a file
w = csv.DictWriter(out, fieldnames=cols, lineterminator='\n')
w.writeheader()
w.writerows(rows) # missing keys become empty cells
print(out.getvalue().splitlines()[0]) # → id,name,city
print(out.getvalue().splitlines()[2]) # → 2,"Ben, Jr.",
text = 'id,zip\n1,007\n'
print(json.dumps(list(csv.DictReader(io.StringIO(text))))) # → [{"id": "1", "zip": "007"}] every value stays a string
JavaScript has no CSV module, but the quoting rule fits in one line:
const rows = [{ id: 1, name: 'Ana' }, { id: 2, name: 'Ben, Jr.', note: 'said "hi"' }];
const cols = [...new Set(rows.flatMap(Object.keys))];
const cell = (v) => { const s = v == null ? '' : String(v); return /[",\r\n]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s; };
const csv = [cols.join(','), ...rows.map((r) => cols.map((c) => cell(r[c])).join(','))].join('\r\n');
console.log(csv.split('\r\n')[0]); // → id,name,note
console.log(csv.split('\r\n')[2]); // → 2,"Ben, Jr.","said ""hi"""
PowerShell: ConvertTo-Csv (5.1) quotes every field, and both directions keep values as strings. It does not flatten nested objects, which come out as text like @{name=Ana}.
$rows = '[{"id":1,"name":"Ana"},{"id":2,"name":"Ben, Jr."}]' | ConvertFrom-Json
$csv = $rows | ConvertTo-Csv -NoTypeInformation # Export-Csv -Path out.csv writes a file
$csv[0] # → "id","name"
$csv[2] # → "2","Ben, Jr."
'id,zip', '1,007' | ConvertFrom-Csv | ConvertTo-Json -Compress # → {"id":"1","zip":"007"}Questions
What JSON shape does it need?
An array of objects, like [{"id": 1, "name": "Ana"}, {"id": 2, "name": "Ben"}]. A single object is treated as one row.
Can it convert CSV to JSON?
Yes. Switch the direction to CSV → JSON. The first row is used as the keys.
Is the CSV safe to open in Excel?
Cells that start with =, +, - or @ (other than plain numbers) get a leading apostrophe, so a spreadsheet shows them as text instead of running them as formulas. The downloaded file also starts with a UTF-8 marker so accented characters display correctly.
Why did my leading zeros disappear?
The converter keeps them: 007 stays the string "007" in both directions. Spreadsheets drop them when they open a CSV and guess that the column is numeric. Import the file with the column type set to Text instead of double-clicking it.
How are null values written?
As empty cells. Converting that CSV back gives empty strings, so if you need to tell null from a missing value or an empty string, keep the data in JSON or write a marker such as NULL yourself.
Can it convert a JSON object of objects, keyed by ID?
Not directly: a single object is treated as one row, so {"a": {...}, "b": {...}} becomes one wide row with columns like a.name and b.name. Turn it into an array first, for example with Object.values(data) or Object.entries in JavaScript.