How to Convert JSON to CSV
Converting JSON arrays to CSV (Comma-Separated Values) format is a common task when exporting data for spreadsheet tools like Microsoft Excel or Google Sheets. While JSON represents data hierarchically, CSV requires a flat, two-dimensional table structure.
In this guide, we'll explain how to parse and convert JSON files into clean, readable CSV tables.
Flat vs Nested Objects
If your JSON is an array of flat objects, the conversion is straightforward.
Input JSON:
[
{ "id": 1, "name": "Alice", "role": "Admin" },
{ "id": 2, "name": "Bob", "role": "User" }
]Output CSV:
"id","name","role"
"1","Alice","Admin"
"2","Bob","User"The object keys act as columns (the header row), and each object in the array represents a row in the table.
Delimiter Options
While commas are the default separator in CSV, you can also format tables using other delimiters:
- Semicolon (`;`): Standard separator in many European regions.
- Tab (`\t`): Used to create Tab-Separated Values (TSV) files.
JSON to CSV
Convert JSON arrays or objects into flat CSV tables.
Resolving Nested Data
If your JSON contains nested objects:
{
"name": "Jane",
"address": { "city": "Boston", "zip": "02108" }
}You have to flatten the structure before converting it to CSV, usually by joining keys with dots (e.g., address.city and address.zip) to form unique columns in your table.