Skip to main content
ponderloop

JSON to CSV Converter

Paste a JSON array of objects, an object of arrays or JSON Lines and get CSV or TSV straight away. The example JSON has 3 records and becomes 7 columns (id, name, address.city, tags.0, tags.1, balance, note): nested objects are flattened with dot paths, arrays become indexed columns, and the headers are the union of every key in the order first seen. Fields are quoted the way RFC 4180 requires, and one cell that starts with = gets an apostrophe in front so a spreadsheet does not run it as a formula. Errors show the exact line and column. Everything runs in your browser, so the data never leaves it.

Updated Runs in your browser: nothing you enter is uploadedHow this tool works

Stays in your browser

Replace the example: paste or type a JSON array, an object of arrays or JSON Lines. The result updates as you type. Up to 2,000,000 characters.

Your data is converted on this device and never uploaded. It is not saved either: reload the page and it is gone.

Options

A spreadsheet can run a cell that starts with = + - or @ as a formula (OWASP calls this CSV injection). With protection on, such a cell gets an apostrophe in front so it opens as text. Real JSON numbers are left alone.

Result

Converted 3 records (JSON) to 7 columns.

  • 1 cell was prefixed with an apostrophe because it starts with = + - @ or a tab, which a spreadsheet could run as a formula. Real JSON numbers such as -3.5 are left alone.

Preview

All 3 rows, as they will appear in the file.
idnameaddress.citytags.0tags.1balancenote
1Ada LovelaceLondonmathcode-3.5
2Hopper, GraceNew Yorknavy'=1+1
3Alan "Prof" TuringWilmslow

Counts

Rows
3
Columns
7
Delimiter
comma
Output size
163 bytes

Which JSON shapes it reads

Each input below is converted with the default settings.
ShapeInputCSV resultHow it is read
Array of objects[{"a":1,"b":2},{"a":3,"c":4}]a,b,c ⏎ 1,2, ⏎ 3,,4One row per object; columns are every key in the order first seen.
Array of arrays[[1,2],[3]]value.0,value.1 ⏎ 1,2 ⏎ 3,Each inner array is a row; columns are named value.0, value.1, and so on.
Single object{"a":1,"b":{"c":2}}a,b.c ⏎ 1,2One row.
Object of arrays{"name":["Ada","Grace"],"score":[1,2,3]}name,score ⏎ Ada,1 ⏎ Grace,2 ⏎ ,3Each key is a column and the arrays run side by side; the shorter one is padded with empty cells.
JSON Lines{"a":1} ⏎ {"a":2,"b":"x"}a,b ⏎ 1, ⏎ 2,xOne JSON value per line, each a row. Detected automatically when the text is not one JSON value.

How nested values are flattened

The same input, “[{"id":1,"tags":["a","b"],"geo":{"lat":1.5,"pts":[{"x":1}]}}]”, with one option changed at a time.
OptionCSV resultEffect
Flatten, arrays as indexed columns (default)id,tags.0,tags.1,geo.lat,geo.pts.0.x ⏎ 1,a,b,1.5,1Objects become address.city style columns and each array element gets its own column, tags.0, tags.1.
Flatten, arrays joinedid,tags,geo.lat,geo.pts ⏎ 1,a; b,1.5,"{""x"":1}"A list of plain values becomes one cell, separated by “; ”. A list of objects inside it is written as JSON text.
Flatten, arrays as JSONid,tags,geo.lat,geo.pts ⏎ 1,"[""a"",""b""]",1.5,"[{""x"":1}]"Objects are still flattened, but every array is kept whole as JSON text in one cell.
No flatteningid,tags,geo ⏎ 1,"[""a"",""b""]","{""lat"":1.5,""pts"":[{""x"":1}]}"Each nested object or array is one cell of JSON text under its top-level key.

How columns are ordered

The input is “[{"b":1,"a":2},{"c":3,"a":4}]”: the first object has the keys b and a, the second a and c.
OptionCSV resultRule
First seen (default)b,a,c ⏎ 1,2, ⏎ ,4,3Keys are added as they first appear, so the file follows the order of your data. A record without a key leaves that cell empty.
Sorteda,b,c ⏎ 2,1, ⏎ 4,,3Columns are put in alphabetical order, with numbers in natural order (tags.2 before tags.10).

When a field is quoted (RFC 4180)

Written with the comma delimiter.
ValueCSV fieldWhy
plainplainNothing special, so no quotes.
a,b"a,b"Holds the comma delimiter, so it is quoted.
say "hi""say ""hi"""Holds a double quote, so it is quoted and the quote is doubled.
line one ⏎ line two"line one ⏎ line two"Holds a line break, so it is quoted and the break stays inside the field.
padded " padded "Spaces at either end are kept by quoting, so readers do not trim them.

What formula protection changes

Cells that start with = + - @ (or a tab) get a leading apostrophe. Real JSON numbers are never changed.
JSON stringProtection onProtection off
=SUM(A1:A9)'=SUM(A1:A9)=SUM(A1:A9)
+1 555 0100'+1 555 0100+1 555 0100
-2+3'-2+3-2+3
@user'@user@user
a=ba=ba=b
2024-01-152024-01-152024-01-15

How errors are reported

The line and column count characters from 1, as in a text editor. For JSON Lines the position is in the whole text.
InputPositionMessage
[{"a":1},{"a":}]line 1, column 15Unexpected “}”; expected a value
{"a" 1}line 1, column 6Unexpected “1”; expected “:” after the key
{"a":1} ⏎ {"a":2} ⏎ {"a":x}line 3, column 6Unexpected “x”; expected a value

How to convert JSON to CSV

  1. Paste your JSON. Replace the example with a JSON array of objects, an object of arrays, or JSON Lines. The format is detected for you; the Options section lets you force it.
  2. Choose how to flatten. Leave nested objects flattened to dot paths such as address.city, and pick whether arrays become indexed columns (tags.0, tags.1), one joined cell, or JSON text.
  3. Pick the delimiter and line ending. Choose comma, semicolon, tab (TSV) or pipe, and LF or CRLF. RFC 4180 specifies CRLF; most tools read either.
  4. Check the preview. The table shows the first 50 rows exactly as they will appear in the file. A message under the result tells you what was flattened, protected or joined.
  5. Copy or download. Copy the CSV or download it as a .csv (or .tsv) file. Tick the byte order mark option if Excel shows accented letters wrongly. Nothing is uploaded.

Frequently asked questions

How do I convert JSON to CSV?
Paste the JSON into the box above and copy or download the CSV. With an array of objects, each object becomes a row and the columns are all the keys found in any object. Nested objects are flattened to dot paths and arrays to indexed columns unless you choose otherwise. To go the other way, from a CSV file to JSON, use the CSV to JSON converter.
How are nested objects and arrays handled?
Nested objects are flattened to columns named by their path, so {"address":{"city":"London"}} gives a column address.city. Arrays can become indexed columns (tags.0, tags.1), one cell with the values joined by a separator, or one cell of JSON text. Switch flattening off to keep every nested value as JSON text in a single cell.
What is CSV injection, and what does the apostrophe do?
When a spreadsheet opens a CSV, a cell that starts with =, +, - or @ can be read as a formula. If the data came from someone else, that cell may run a formula that leaks data or opens a link; OWASP calls this CSV injection or formula injection. Prefixing the cell with an apostrophe makes the spreadsheet show it as text. The protection is on by default; turn it off if you feed the file to a program that must see the exact original text.
Why is my negative number not prefixed with an apostrophe?
Real JSON numbers such as -3.5 cannot be formulas, so they are left as numbers. A string that merely looks like one, for example "-3.5" in quotes or a phone number such as "+1 555 0100", starts with a trigger character and does get the apostrophe.
Which CSV format does it write?
The format of RFC 4180: fields separated by the delimiter, records ended by a line break, and a field wrapped in double quotes when it holds the delimiter, a double quote or a line break, with each inner quote doubled. You can choose CRLF, which the RFC specifies, or LF. The last record has no trailing line break.
How are the columns chosen and ordered?
The columns are the union of the keys of all records, in the order first seen, so a key that only appears in the tenth record still gets a column and earlier rows are left empty there. Tick “Sort columns” for alphabetical order instead.
Can it read JSON Lines or an object of arrays?
Yes. JSON Lines (one JSON value per line, also called NDJSON) is recognised when the text is not a single JSON value, and an error in line 40 is reported at line 40. An object whose values are all arrays, such as {"name":["Ada","Grace"],"score":[1,2]}, is read as columns. You can force either reading in Options.
Can I get a TSV or a semicolon file for European Excel?
Yes. Choose tab for TSV, or semicolon for spreadsheets whose list separator is a semicolon (common where the comma is the decimal mark). The download is named converted.tsv for tab and converted.csv otherwise.
What does the byte order mark option do?
It puts the three bytes EF BB BF at the start of the downloaded file. Excel on Windows uses them to recognise UTF-8; without them accented letters and non-Latin text may be shown wrongly. Other programs may show the mark as a stray character, so it is off by default.
Are big numbers kept exact?
Yes. Numbers are copied into the CSV cell exactly as they are written in your JSON, digit for digit, instead of going through JavaScript numbers: an ID like 12345678901234567890 stays whole (JSON.parse would round it to 12345678901234567000) and a price of 1.10 keeps its trailing zero. A spreadsheet may still round long numbers when it opens the file, so import such columns as text.
How large a file can I convert?
Up to 2,000,000 characters, about 2 MB. Above that the page tells you so instead of converting, because a browser tab would stall. Split the data and convert the parts one at a time. The preview shows only the first 50 rows, but the copied and downloaded file has every row.
Is my data uploaded anywhere?
No. The conversion runs in your browser and the JSON you paste and the CSV it becomes are never uploaded, stored or logged; it is gone when you close or reload the page. The download is built in memory from a Blob. The only thing the site records, if you allow analytics, is that a button was used, never any of the data.

How it works

The JSON is read by a strict RFC 8259 parser that keeps numbers as written and keys in the order written, and reports an error with its line and column. If the whole text is not one JSON value but its first line is, and there is more than one line, each non-blank line is read as a JSON Lines record. A top-level array gives one record per element, a top-level object whose values are all arrays is read as columns (row i takes element i of each array), and any other object is one record. A record that is not an object is written under the column value. Each record is flattened depth-first: an object adds its key to the path with a dot, an array element adds its index, and a plain value becomes a cell; with “joined” the plain elements of an array are joined into one cell, and with “JSON” or with flattening off a nested value is written as compact JSON text. An empty object or array adds no column. The columns are the union of all paths, in the order first seen or sorted in natural order. Cells are written with the quoting rules of RFC 4180: a field is quoted when it contains the delimiter, a double quote or a line break (or has a space or tab at either end), and quotes inside are doubled. Records are joined with LF or CRLF. Formula protection follows the OWASP guidance on CSV injection: any cell, including a header, whose text starts with =, +, -, @, a tab or a carriage return gets a single quote in front. Cells that come from real JSON numbers are exempt, since they cannot be formulas. Input above 2,000,000 characters is refused with a notice. The preview table is built from the same cells as the file, so it shows exactly what a spreadsheet will receive.

Sources

More: Formatters and data convertersAll developer toolsAll toolsHome & DIY calculators