JSON to CSV

Published Updated

Paste or upload a JSON array of objects and get a CSV with one row per object. Nested keys become columns such as address.city and tags.0, and a key found in any object gets a column of its own.

One array in, one table out

The input has to be a JSON array whose items are all objects, such as [{"name": "Jane"}, {"name": "John"}]. Each object becomes a row, and the columns are every key of every object, so a key only the 40th object has still gets a column. Columns follow the order in which keys first appear, except that inside each object, keys that are whole numbers come first, in numeric order.

Papa Parse writes the file with commas, CRLF line endings and quotes where needed, as in RFC 4180: fields with commas, quotes or line breaks are quoted, and an inner quote is doubled.

Where each JSON value ends up

In the JSONIn the CSV
"address": {"city": "Boston"}A column address.city holding Boston
"tags": ["a", "b"]Columns tags.0 and tags.1 (JSON to Excel joins them into one cell instead)
"tags": [] or {}A blank cell under tags
true, falsetrue, false
null, or the key missingA blank cell
"zip": "02134"02134, with its zero
"note": "a, b""a, b", quoted because of the comma
"v": "=SUM(1,2)"'=SUM(1,2), with an apostrophe in front

The formula guard and its side effect

A cell starting with = or @ can run as a command when opened, the attack OWASP calls CSV injection. OWASP's risky first characters are =, +, -, @, tab, carriage return, line feed and full-width forms such as =, and a leading single quote is one of its fixes. The tool adds it for the first six, in values and column names; a line feed or full-width sign at the start passes unchanged.

Harmless text pays too: the phone number "+44 20 7946 0000" stored as a string becomes '+44 20 7946 0000. OWASP adds that Excel can lose the protection after a save and reopen.

The CSV text this page writes, checked case by case

Each JSON input below went through the tool's own conversion code, run in Node.js 22.23.1 with Papa Parse 5.5.4. The right column is the file's text, line by line:

JSON inputCSV written
[{"a":1,"b":2},{"b":3,"c":4},{"c":5}]a,b,c then 1,2, then ,3,4 then ,,5: a missing key is an empty cell
[{"a":null,"b":"","c":0},{"c":false}]a,b,c then ,,0 then ,,false: null and an empty string look the same
[{"order":7,"items":[{"sku":"A1","qty":2},{"sku":"B2","qty":1}]}]order,items.0.sku,items.0.qty,items.1.sku,items.1.qty then 7,A1,2,B2,1
[{"n1":1.0,"n2":1e21,"n3":-0,"n4":0.1,"n5":12345678901234567890,"n6":1e-7}]1,1e+21,0,0.1,12345678901234567000,1e-7 under the header row
[{"a":"x, y","b":"say \"hi\"","c":"line1\nline2"}]"x, y","say ""hi""","line1 then line2": the line break stays inside the quotes
[{"a":" lead","b":"trail ","c":"in side"}]" lead","trail ",in side: a space at either end gets quotes
[{"b":1,"a":2,"10":3,"2":4}]2,10,b,a then 4,3,1,2: whole-number keys first
[{"=cmd":1,"'=cmd":2}]'=cmd,'=cmd (2) then 1,2: the guarded name clashes, so the second gets (2)
[{"":{"a":1},"a":2}]a then 2: an empty key holding an object shares the column a, and the 1 is lost

Rows end with CRLF and the last row has no line break after it. RFC 4180 allows both: "The last record in the file may or may not have an ending line break." A line break inside a value is written as it is in the JSON, so a \n stays a lone LF inside the quotes.

For size, 1,000 generated product records with a nested dims object and a three-item tags array took 249,227 bytes as indented JSON and 146,226 bytes minified. The CSV was 65,294 bytes with 11 columns, from id to dims.unit, because each key is written once in the header instead of in every row.

The downloaded file, byte by byte

The real tool component, measured in Google Chrome 157, Firefox 155 and Playwright's WebKit build (not the Safari app) on generated JSON, wrote identical files and showed the same messages in all three. A two-row sample with an emoji key, accented and non-Latin text, a quote, a comma and a line break inside a value gave a 102-byte file:

What we checkedWhat the file holds
First bytes6E 61 6D, the letters of the first header name: no byte order mark
Line endsCRLF between rows and none after the last row; the line break inside a value stays a lone LF inside the quotes
Non-ASCII textUTF-8 in names and values alike: é is C3 A9, 東 is E6 9D B1, 🙂 is F0 9F 99 82
Type of the downloadtext/csv, with no charset parameter
File namedata.csv for pasted text; orders.v2.json gives orders.v2.csv, Data.JSON gives Data.csv, report.json.txt gives report.json.csv, export gives export.csv, and a file named only .json gives .csv
Card above the preview"2 rows · 5 columns · 102 B", the size of the file itself
Previewthe same text as the file, with each CRLF shown as a line break

The preview counts lines, not rows. Sixty rows, one of them holding a two-line value, make 61 records with the header and 62 lines, so the label reads "Preview (first 50 of 62 lines)" and the box ends with "// ... 12 more lines". The download and Copy always hold every row.

What the apostrophe guard leaves in each cell

Each value below was the only cell of a one-row file. The right column is that cell exactly as written, with \t, \r and \n standing for a tab, a carriage return and a line feed:

String in the JSONCell in the file
=1+1, +44 20, @SUM(A1)'=1+1, '+44 20, '@SUM(A1)
the string "-5"; the number -5'-5; -5
a tab, then =1'\t=1, not quoted
a carriage return, then =1"'\r=1", quoted
a line feed, then =1"\n=1", quoted, no apostrophe
full-width =1+1, +1, -1, @A1unchanged, no apostrophe
a space, then =1" =1", quoted, no apostrophe
'=1, already starting with an apostrophe'=1; no second apostrophe is added
column names =HYPERLINK(1), @x, =ythe header row '=HYPERLINK(1),'@x,=y

Messages and conversion time

  • Invalid JSON, JSON Lines and pasted text that starts with a byte order mark all get "This doesn't look like valid JSON. Check for a missing bracket, quote, or trailing comma." The browser's own parser message is not shown, so the wording is the same in all three engines.
  • A .json file that starts with a byte order mark converts: reading the file drops the mark.
  • A lone object gets "Expected a JSON array of objects" and an empty array "This JSON array is empty". For [1,2], or an array whose second item is null, the message names the item: "item 1 isn't", "item 2 isn't".
  • [{},{}] gets "No fields were found in this JSON, so there are no columns to write." A key named __proto__ gets its own column like any other key.
  • Objects nested 500 deep inside the array convert, to one column named a.a.a and so on; at 501 the page says the JSON is more than 500 levels deep.
  • Text made only of spaces and line breaks shows no Convert button.

Timings: records with 10 columns, read from a .json file, measured from the Convert click until the Download CSV link appeared, median of 5 runs:

Records (JSON size, CSV size)Chrome 157Firefox 155the WebKit build
1,000 (126,754 bytes, 49.6 KB)6 ms16 ms6 ms
10,000 (1,287,592 bytes, 515.3 KB)43 ms58 ms29 ms
100,000 (13,075,954 bytes, 5.22 MB)425 ms461 ms300 ms
500,000 (66,268,663 bytes, 26.96 MB)3,917 ms2,342 ms1,704 ms

No size failed or was cut. The 500,000-record runs spread the most: Chrome 157 took between 3,043 and 13,877 ms, and two of the five WebKit runs took 82,122 and 86,354 ms while the other three took 1,491 to 1,704 ms.

Turning JSON into rows

  1. Step 1

    Paste JSON or add a file

    Use the box for pasted text or drop a .json file. The input must be one array, with an object for each row.

  2. Step 2

    Convert

    The JSON is checked, every object flattened and the CSV written. Errors name the problem, such as item 3 not being an object.

  3. Step 3

    Download or copy

    The card shows rows, columns and size, with a preview of the first 50 lines. The file keeps your upload's name with .csv, or data.csv for pasted text.

Checks before you import the CSV

  • Long numbers. Under RFC 8259, parsers are sure to agree on integers within plus or minus 2^53 minus 1; longer ones are rounded before the CSV is written.
  • Clashing names. A literal key "a.b" and a nested a.b share one column, and the later value wins silently. A key repeated in one object keeps its last value, as RFC 8259 says many parsers do.
  • Opening in Excel. Microsoft's page on UTF-8 CSV files points files without a byte order mark to From Text/CSV.
  • Messy input. Tidy or validate the JSON first with JSON Formatter; for a ready workbook, JSON to Excel skips the CSV step.

JSON to CSV: common questions

Why do some cells start with an apostrophe?

Text beginning with =, +, -, @, a tab or a carriage return could run as a formula in a spreadsheet, so the tool puts an apostrophe in front. Numbers are left alone: -5 stays -5, but the string "-5" becomes '-5.

Can it convert one JSON object, or JSON Lines?

Not directly. A lone object gets "Expected a JSON array of objects", and JSON Lines fails as invalid JSON. Wrap the objects in square brackets with commas between, and they convert.

How are arrays inside an object handled?

Each element gets its own numbered column: tags.0, tags.1 and so on, and an array of objects gives columns such as items.0.sku. An empty array or object leaves one blank cell under its own name.

Why did a long ID number change?

JSON numbers are read as 64-bit floating point, exact for whole numbers no larger than 9,007,199,254,740,991, so 12345678901234567890 comes out as 12345678901234567000. Store such IDs as strings and every digit survives.

Why are accented letters garbled when Excel opens the file?

The CSV is UTF-8 without a byte order mark, which Microsoft says a UTF-8 CSV needs to open normally. Import it through Data, Get Data, From File, From Text/CSV, or use JSON to Excel.

How big a file can it take?

The code sets no row limit; the whole text is parsed at once in the tab, so very large files depend on your device's memory. Only nesting is capped: past 500 levels you get an error rather than a stuck page.

Why are my columns in a different order than my JSON?

Keys that are whole numbers, such as "2" or "10", are put first inside each object, in numeric order, before the other keys. That is how JavaScript orders object keys after parsing, so {"b":1,"a":2,"10":3,"2":4} gives the header 2,10,b,a. Other keys keep the order in which they first appear.

Can I tell null from an empty string in the CSV?

No. Both become an empty cell, and so does a key the object does not have. 0 and false are written out as 0 and false. If the difference matters, replace null with a marker string such as NULL in the JSON before converting.

Does the CSV end with a line break?

No. Rows are separated by CRLF and the file ends right after the last value. RFC 4180 allows a last record with or without an ending line break.

How much smaller is the CSV than the JSON?

For 1,000 generated records with 11 columns, the CSV was 65,294 bytes against 146,226 bytes of minified JSON, 55% smaller, because the keys appear once in the header row instead of in every object.

What encoding and line endings does the CSV use?

UTF-8 with no byte order mark, and CRLF between rows with no line break after the last one. In Chrome 157, Firefox 155 and the WebKit build the file began with the bytes of the first header name, é was written as C3 A9 and 🙂 as F0 9F 99 82, and the browser labelled the download text/csv.

Why does the preview count more lines than I have rows?

It counts lines, and the header is one of them, as is each extra line of a value that holds a line break. Sixty rows with one two-line value showed "Preview (first 50 of 62 lines)". The download and Copy hold all the rows.

Can it convert a JSON file with 500,000 records?

Yes. A generated file of 66,268,663 bytes holding 500,000 records with 10 columns became a CSV the card listed as 26.96 MB. The median time from click to download link was 3,917 ms in Chrome 157, 2,342 ms in Firefox 155 and 1,704 ms in the WebKit build, though single runs took up to 13.9 seconds in Chrome and 86 seconds in the WebKit build.

Why does it say no fields were found?

Every object in the array was empty, so there is no column to write. [{},{}] gets that message instead of an empty file. One key is enough: [{},{"a":1}] gives the column a, with an empty line for the first object, and an empty nested object such as {"tags":{}} still gives a tags column.

Related Tools