JSON to CSV

Paste JSON or open a .json file and download a CSV. Nested objects turn into dotted columns such as address.city, lists stay as JSON text in one cell, and the data is converted in your browser tab, not uploaded.

JSON to CSV

How to convert JSON to CSV

  1. Paste your JSON into the JSON box, or click Open a JSON file and choose a .json or .txt file. The input can be a list of objects, a list of lists, or one object.
  2. Read the line under the box. It says how many rows and columns were written, or why the text was refused.
  3. Leave Turn nested objects into columns ticked to get headers such as address.city. Untick it to keep each nested object as JSON text in a single cell.
  4. Choose the Delimiter your spreadsheet expects, and untick Write a header row with the column names if you want data lines only.
  5. Tick the formula protection if the text comes from people you do not control, then use Copy CSV or Download .csv.

What goes in and what comes out

The page takes a list of objects, a list of lists, or a single object, which becomes one row. Columns follow the order in which keys first appear, reading from the first object down. A key that shows up only in a later object is added on the right, and the rows without it get an empty cell. Our 192-byte sample (three people, two of them with a skills list) came out as the header id,name,skills plus three rows, and the page reported 3 rows and 3 columns.

The converter is Papa Parse, a common CSV library, fetched from the cdnjs network the first time you paste, type or open something. The browser checks the file against a fixed hash before running it. That download is the only request the converter makes: in our log it was a single GET with no body, and no request carried the JSON we pasted or opened. Like every GramFile page, this one also loads Google ad and analytics scripts; we blocked them during the test, and none of the requests we saw had a body. Only Chromium was tested.

Nested objects: dotted columns or one JSON cell

With Turn nested objects into columns ticked (it is on by default), every object inside an object is opened and its keys are joined with a dot. We tested it on {"id":1,"a":{"b":{"c":{"d":"deep"}}},"e":{},"f":[]} followed by {"id":2,"a":{"b":5}}. The header came out as id,a.b.c.d,e,f,a.b. Row 1 has deep under a.b.c.d. Row 2 has 5 under a.b, a column that only appeared with the second object, so it sits at the far right. The empty object e became an empty cell.

Untick the option and the same file gives id,a,e,f. Column a then holds the text {"b":{"c":{"d":"deep"}}} in row 1 and {"b":5} in row 2, and e holds {}.

Two cases need a warning. First, our nested.json sample came out identical with the option on and off, because its only nested objects sit inside a list, and lists are never opened (next section). If your file looks unflattened, check whether the nesting is inside lists. Second, a key that is itself called a.b collides with a nested a containing b. We fed in {"a.b":1,"a":{"b":2}} and got one column, a.b, holding 2. The 1 was dropped and the page said nothing.

Lists inside the data

A list is not split into columns or rows. It is written as JSON text in one cell, and the cell is wrapped in quotation marks because the text contains commas and quotes. In our nested sample the tags cell holds ["tools","pdf","images"]. The offices cell holds both office objects as one piece of text, coordinates included, so geo never gets columns of its own. A spreadsheet sees that cell as a single string.

Three kinds of empty look different in the output. A key missing from an object gives an empty cell (Lukas has no skills). A null value gives an empty cell too (the notes column). An empty list gives the text [] (Mei).

There is no option for one row per list item. If you need that shape, reshape the JSON before you paste it.

Numbers, long IDs and leading zeros

Values are written the way JavaScript prints them. In our number test 120.50 became 120.5, true and false stayed as those words, 1e21 became 1e+21 and 0.0000001 became 1e-7. A string is copied as it is, so the zip code "00501" is written as 00501. Spreadsheet programs often turn that into 501 when they open the file. We did not test that, so check a column of codes after importing, and import it as text if the zeros matter.

Large integers are the one place where data changes before the page sees it. Your browser reads a JSON number as a double, which is exact only up to 9,007,199,254,740,991. We put 9007199254740993 into the file twice. As a bare number it came out as 9007199254740992. As a quoted string it came out as 9007199254740993. If your IDs are long, quote them in the JSON.

Formula protection

A spreadsheet can run a cell that starts with an equals sign, and it may treat a leading plus, minus or at sign the same way. When the JSON holds text from users, a cell like =SUM(1+1) can end up executed on someone's machine. The protection option is off by default. When it is on, every text cell that starts with =, +, - or @ gets an apostrophe in front.

We ran one object with five such values. With the option off, =SUM(1+1), +49 30 1234, -x and @cmd were written unchanged. With it on, each one gained a leading apostrophe. The phone number shows the downside, since it is harmless text and still got the apostrophe. A quoted "-5" was changed too, while a real JSON number -5 was left alone. Inside the CSV the apostrophe is ordinary cell text, and we did not check how each spreadsheet program displays it.

Excel, delimiters and the header row

Download .csv saves a file called converted.csv. Lines end with a carriage return and a line feed, and there is no line break after the last row. With the Excel option ticked, which is the default, the file starts with the three bytes EF BB BF, a UTF-8 marker. Excel generally needs it to read accents and non-Latin letters correctly in a CSV. We did not open our files in Excel, so we checked the bytes. A test row with Émilie, Zürich, 小明 and قهوة was 56 bytes with the marker and 53 without, and the text read back the same in both. Untick the option if the file goes to a script or a database loader, since some programs show the marker as an odd character in the first column name.

The delimiter defaults to a comma. If your spreadsheet puts everything into column A, try a semicolon, which spreadsheets in many countries expect. Tab and pipe also work. The sample header read id;name;skills, id|name|skills and, with tabs, the same names separated by tab characters.

Unticking Write a header row removes the first line: the sample gave 3 lines instead of 4. A list of lists never gets a header line, because its first inner list is already a row. When the inner lists have different lengths, the short rows are padded with empty cells.

Errors and the 10 MB limit

Invalid JSON is reported with the message from your browser, so the wording depends on the browser. Chromium said Expected double-quoted property name in JSON at position 8 (line 1 column 9) for a list with a trailing comma, and for our invalid.json sample it quoted a snippet around the stray comma without a line number. For exact positions, paste the text into the JSON formatter first. A single value such as 5 is refused with a message that the JSON must be a list or an object. An empty list is refused because there is nothing to write, and a list that mixes objects and lists is refused with its own message. A file of only blank lines gave no output and no message.

Files up to 10 MB are accepted. A 9,516,766-byte file with 105,000 objects took about 4 seconds and produced a 4,884,194-byte CSV, roughly half the input size, because the keys are written once in the header instead of in every row. The box shows only the first 300 KB and says so. Copy CSV and Download .csv give everything, and the download had the header plus 105,000 lines. A 10.9 MB file was turned away with a message asking for a smaller piece.

Related conversions

To go the other way, from a table back to JSON, use CSV to JSON. If the destination is an .xlsx workbook, the CSV and Excel converter reads and writes spreadsheets directly. The JSON formatter is the place to validate or tidy JSON before you convert it.

Measured results

Test runs of the page in headless Chromium with Papa Parse 5.4.1. Each cell was read back from the output box or from the downloaded file.
InputSettingWhat came out
nested.json, 444 bytesFlatten on1 row, 8 columns: company, founded, active, tags, offices, notes, ratio, big. tags and offices are JSON text, notes is empty
nested.jsonFlatten offIdentical to the row above, since every object sits inside a list
deep.json, 74 bytesFlatten onColumns id, a.b.c.d, e, f, a.b. e is empty, f is []
deep.jsonFlatten offColumns id, a, e, f. a holds {"b":{"c":{"d":"deep"}}}, e holds {}
array-of-objects.json, 192 bytesDefaults3 rows, columns id, name, skills. Lukas has an empty skills cell, Mei has []
array-of-objects.jsonSemicolon, tab, pipeHeader line separated by ; then tab characters, then |
formulas.json, 113 bytesProtect on'=SUM(1+1), '+49 30 1234, '-x, '@cmd and '-5 for the text -5; the number -5 unchanged
numbers.json, 153 bytesDefaults120.5, 00501, true, false, empty for null, 9007199254740992 from a number, 9007199254740993 from a string, 1e+21, 1e-7
unicode.json, 72 bytesMarker on and off56 bytes starting EF BB BF, then 53 bytes; same text
9.5 MB list of 105,000 objectsDefaults4,884,194 byte CSV in about 4 s; the box shows the first 300 KB

When a script is the better choice

A scripting language such as Python or a command-line JSON tool such as jq is the better fit when you need one row per list item, when the JSON is larger than 10 MB, or when the conversion has to run on a schedule. Reshape the data there, then use this page for a quick check of how a sample will look. The CSV it produces opens in Microsoft Excel or LibreOffice.

Frequently asked questions

Is my JSON uploaded?

No. The JSON is converted inside your browser tab. The page fetches the Papa Parse library from cdnjs once, and that fetch carries none of your text: our request log showed one GET without a body, and no request contained what we pasted or opened.

What happens to nested objects?

With the default option on, each nested key becomes a dotted column such as a.b.c.d. With it off, the nested object is written as JSON text in one cell. Objects inside lists are never opened.

What happens to arrays?

A list is written as JSON text in one cell, for example ["tools","pdf","images"]. An empty list is written as [], while a missing key and a null value both give an empty cell.

Can I get one row for each item in a list?

Not on this page. Reshape the JSON first so that each item is its own object in the top-level list.

Why did my long ID change?

Your browser reads a bare JSON number as a double, which is exact only up to 9,007,199,254,740,991. In our test 9007199254740993 came out as 9007199254740992. Put the ID in quotes in the JSON and every digit is kept.

Why do some cells start with an apostrophe?

That is the formula protection option. It adds an apostrophe to text that starts with =, +, - or @, so a spreadsheet does not run it as a formula. Phone numbers that start with a plus sign are changed too.

Will Excel show accents correctly?

Keep the UTF-8 marker option ticked, which is the default. It adds three bytes at the start of the file for Excel. We checked the bytes but did not open the file in Excel.

How large a file can I convert?

Files up to 10 MB are accepted. Our 9.5 MB test with 105,000 objects finished in about 4 seconds. Only the first 300 KB appears in the box, and Copy CSV and Download .csv use the full output.