How to Convert JSON to CSV or Excel
XUtilHub Team ·
APIs and apps export data as JSON, but your manager wants it in Excel. Converting JSON to CSV or a spreadsheet is easy for flat data, and needs a little thought when the JSON is nested.
The easy case: an array of flat objects
[
{ "id": 1, "name": "Ali", "city": "Lahore" },
{ "id": 2, "name": "Sara", "city": "Karachi" }
]
Each object becomes a row and each key becomes a column:
id,name,city
1,Ali,Lahore
2,Sara,Karachi
Paste it into JSON to CSV or, to get a real .xlsx file with columns already set up, JSON to Excel.
Nested objects: flattening
{ "id": 1, "name": "Ali", "address": { "city": "Lahore", "zip": "54000" } }
CSV has no nesting, so nested keys are usually flattened with dots:
id,name,address.city,address.zip
1,Ali,Lahore,54000
Arrays inside objects
{ "id": 1, "name": "Ali", "phones": ["0300-1234567", "042-1234567"] }
There are a few ways to handle these, and the right one depends on what you'll do with the data:
- Join the values into one cell:
0300-1234567; 042-1234567. - Number the columns:
phones.0,phones.1. - One row per item, repeating the parent's data. Best for arrays of objects such as order items.
Missing and extra keys
Objects in real data don't always have the same keys. A good converter collects every key from every object to build the header row, and leaves cells empty where a value is missing.
Excel gotchas
- Leading zeros vanish. Excel turns
0300into300and long ID numbers into scientific notation. Importing as text, or using the.xlsxexport, avoids this. - Non-English text looks garbled. CSV files need UTF-8 encoding; some versions of Excel need a byte-order mark to recognise it. Urdu, Arabic and accented names display correctly in an
.xlsxfile. - Commas and quotes in values must be escaped inside quotes. A proper converter does this for you.
- Dates may be reformatted by Excel to your local format.
Going the other way
Have a spreadsheet you need as JSON for an app or API? Export it to CSV and use CSV to JSON. Column headers become keys.
Very large files
For files of hundreds of megabytes, a command-line tool such as jq or a short script is better than a browser converter. For everyday exports, the tools above handle thousands of rows in a moment, in your browser.
Tools mentioned in this article
JSON to CSV
Convert JSON arrays to CSV. Nested objects are flattened to dot-notation columns. Choose the delimiter and download a .csv file.
JSON to Excel
Convert JSON arrays to an Excel spreadsheet (.xlsx). Nested fields are flattened to columns. Free, no upload.
CSV to JSONNEW
Convert CSV or TSV data to a JSON array of objects, with automatic delimiter detection, header rows and number and boolean conversion.