How to convert JSON to CSV
A CSV file is a table: one row per record and one column per field. To turn JSON into CSV, first decide which JSON objects should become rows. Then write their keys as headers and their values as cells. You can do that in your browser, in Excel, or with a short Python script.
What does JSON to CSV conversion look like?
This JSON array has two records. Each object becomes a CSV row; its keys become the header columns.
input.json
[
{ "name": "Asha", "age": 28, "city": "Delhi" },
{ "name": "Luis", "age": 31, "city": "Austin" }
]output.csv
name,age,city
Asha,28,Delhi
Luis,31,AustinThe visible line breaks above represent CSV records. The downloadable file uses CRLF line endings. Commas inside values are enclosed in double quotes, and a double quote inside a value is doubled, following the common CSV format described by RFC 4180.
How do I convert a JSON file to CSV online?
- Open the JSON to CSV converter.
- Paste JSON, choose a
.jsonfile, or drop the file onto the tool. - Choose a separator: comma for standard CSV, semicolon if your importer expects it, or tab for TSV.
- Select Convert to CSV, inspect the row preview or CSV text, then copy or download the result.
The conversion runs in your browser. The file is not uploaded. You can also use Try an example to see how nested fields are handled before choosing your own file.
Which JSON shapes convert cleanly to CSV?
| JSON shape | CSV result in our tool |
|---|---|
| Array of objects | One row per object, with the union of all keys as columns. Missing fields are blank. |
| One object | One row. An object whose only field is an array of objects uses that array as the rows. |
| Nested object | Columns use paths such as shipping.city. |
| Array inside a record | The complete array is kept as JSON text in one cell. |
| Array of arrays | Each inner array becomes a row, without a generated header. |
| JSON Lines | Each line becomes a row, like an array of records. |
CSV cannot represent nested objects or lists as native values. Flattening or storing JSON text is a choice, and the receiver must know how to read it. If you need nested items in separate, related tables, use the JSON to Excel converter instead.
How do I convert JSON to CSV in Excel?
- In a supported Excel version, choose Data → Get Data → From File → From JSON and open the JSON file.
- In Power Query, turn a top-level list into a table, then expand the record columns you need. Expand nested records or lists deliberately so each final row has the fields you want.
- Load the table to a worksheet. Review the columns and data types, especially IDs with leading zeros and long numbers.
- Choose File → Save As and select a CSV format. Excel saves the active sheet as CSV.
Microsoft documents the From JSON command in Power Query and saving the active worksheet as CSV. The exact expansion steps depend on whether your JSON starts with a list or a record. If you only need CSV, the browser converter skips the worksheet setup.
How do I convert JSON to CSV in Python?
For a JSON array of flat objects, Python’s standard json and csv modules are enough. Save this as convert.py beside input.json, then run python convert.py:
import csv
import json
with open("input.json", encoding="utf-8") as source:
rows = json.load(source)
if not isinstance(rows, list) or not all(isinstance(row, dict) for row in rows):
raise ValueError("Expected a JSON array of objects")
if not rows:
raise ValueError("No records to write")
fields = list(dict.fromkeys(key for row in rows for key in row))
with open("output.csv", "w", encoding="utf-8", newline="") as target:
writer = csv.DictWriter(target, fieldnames=fields)
writer.writeheader()
writer.writerows(rows)json.load reads the file. csv.DictWriter writes a header and records. The field list includes keys from every object, so a field that first appears later is retained. newline="" prevents extra blank lines on some systems. This example expects flat values; flatten nested objects or serialize lists before writing them. It writes raw text, so guard formula-like values if the CSV will be opened in a spreadsheet. See the Python JSON documentation and CSV documentation for the module behavior.
What is the best tool for converting JSON to CSV?
For a one-off file, choose a tool that shows the rows before download, explains what it does with nested data, supports the separator your importer expects, and handles data at a size your device can process. For repeatable jobs, Python is useful because the conversion rules live in a script you can rerun and review. For manual cleanup after import, Excel’s Power Query gives you a visual way to select and expand fields.
When the CSV will be opened in a spreadsheet, keep the converter’s formula protection on. It adds an apostrophe before text that could be interpreted as a formula. Turn it off for an exact raw-data import, and check the receiving app’s own safety rules.
How do I convert CSV to JSON?
CSV to JSON is the reverse mapping: the first CSV row supplies the field names, and each later row becomes an object. In Python:
import csv
import json
with open("input.csv", encoding="utf-8-sig", newline="") as source:
rows = list(csv.DictReader(source))
with open("output.json", "w", encoding="utf-8") as target:
json.dump(rows, target, ensure_ascii=False, indent=2)DictReader reads the header and rows. All CSV cell values come back as strings; convert numbers, dates, or booleans explicitly if your JSON needs those types. utf-8-sig also handles CSV files that start with a UTF-8 byte order mark.
Can I convert CSV to JSON in Excel?
Excel can import CSV through Data → Get Data → From File → From Text/CSV, but its ordinary Save As formats do not provide a direct JSON export. For JSON output, use a script or a dedicated CSV to JSON converter after reviewing the columns. Microsoft’s Power Query import guide covers CSV import.
Can I convert a CSV file to JSON in Node.js?
Yes. In an ES module project, this example uses the csv-parse package, installed with npm install csv-parse, because CSV quoting and embedded line breaks need a proper parser. Save it as convert.mjs:
import { readFile, writeFile } from 'node:fs/promises';
import { parse } from 'csv-parse/sync';
const csv = await readFile('input.csv', 'utf8');
const rows = parse(csv, { columns: true, bom: true });
await writeFile('output.json', JSON.stringify(rows, null, 2));If a CSV cell itself contains JSON text, parse that particular cell after reading the CSV. CSV is not JSON, so a Java program reading a CSV file likewise needs a CSV parser first, then a JSON parser for any cells that actually contain JSON.