What JSON to CSV does
JSON to CSV reads JSON and writes it as CSV. The input is parsed first, so a syntax error is reported with its position instead of producing broken output.
JSON to CSV examples
The built-in sample
Input
{"name":"Ada Lovelace","active":true,"tags":["math","code"],"address":{"city":"London"}}Output
name,active,tags,address.city
Ada Lovelace,true,"[""math"",""code""]",LondonThis is the input that the Load sample button fills in.
Nested objects, arrays and missing keys
Input
[{"id":1,"user":{"name":"Ada","langs":["en","fr"]},"note":"a, b"},{"id":2,"user":{"name":"Lin"},"active":false}]Output
id,user.name,user.langs,note,active
1,Ada,"[""en"",""fr""]","a, b",
2,Lin,,,falseuser.name is a flattened column, the langs array is written as JSON text in one cell (with its quotes doubled), "a, b" is quoted because it contains a comma, and a key that a row does not have is left empty.
Each output was produced by running this tool on the input above it.
How it works
Reading JSON. The input is parsed as JSON (RFC 8259). If it is not valid, the conversion stops and the error shows the line and column of the problem.
Writing CSV. Each object becomes a row. Nested objects are flattened into dotted column names such as address.city, arrays are written as JSON text in one cell, and the header is the union of keys from every row. Values containing commas, quotes or line breaks are quoted, with inner quotes doubled.
Details and limits
- There is no fixed size limit: everything runs on your device, so very large inputs depend on its memory.
- It works in current browsers on phones, tablets and computers, and it is free with no account needed.
- Values are carried across without losing anything in ordinary data; the points above list the cases the two formats handle differently.
- The header is the union of the keys of all rows, in the order in which each key is first seen. It is not sorted.
- A top-level object is treated as a single row. A top-level array of plain values, such as
[1,2], gives one column namedvalue. nulland missing keys both become empty cells, so the two cannot be told apart afterwards.- Line breaks inside values are kept inside quotes. Rows are separated by a line feed, not CRLF.
- Input that is not valid JSON stops the tool, and the status line shows where the problem is. The JSON Validator page lists the usual causes.
Questions
Why does one cell contain JSON text?
The value was an array. A table cell can hold only one value, so the array is written as JSON text. Flatten or join the array yourself first if you need separate columns.