How to Convert JSON to CSV (Step-by-Step Guide)
In this guide you will learn how to convert JSON to CSV using an online JSON to CSV converter, Excel/Google Sheets, and simple code examples. We will also cover how to convert JSON files to CSV, handle JSON Lines (NDJSON), and deal with nested JSON.
1. What are JSON and CSV?
Before we convert JSON to CSV, it helps to understand the difference between these two formats:
- JSON (JavaScript Object Notation) is a flexible text format for structured data, widely used in APIs and configuration files.
- CSV (Comma-Separated Values) is a simple table-like format where each row is a record and each column is a field.
When you change JSON to CSV, you are flattening structured objects into tabular data so you can analyze it in Excel, Google Sheets, databases, or BI tools.
2. Method 1 – Convert JSON to CSV with an online converter
If you just want the easiest way of converting JSON to CSV, use an online JSON to CSV converter.
- Open a JSON to CSV converter in your browser.
- Paste your JSON or JSON Lines (NDJSON) into the input area.
- Click the button to convert JSON to CSV format.
- Download the CSV file and open it in Excel or any spreadsheet tool.
Most online tools let you transform JSON to CSV in one click. Some also support options like flattening nested objects, choosing delimiters, or previewing the resulting table.
If you just want to quickly change JSON to CSV online, you can use this free JSON to CSV converter. It lets you paste JSON or JSON Lines and download a ready-to-use CSV file.
Recommended: use a dedicated JSON to CSV converter
A dedicated JSON to CSV converter page usually offers:
- A clear input box for raw JSON or JSON Lines.
- Options to switch between standard JSON and NDJSON.
- A preview table showing the converted CSV.
- A download button for the final CSV.
When you convert JSON to CSV online, always check:
- Whether the tool runs client-side (in your browser).
- How it handles null values and missing fields.
- How nested arrays and objects are flattened.
3. Method 2 – Convert JSON file to CSV with Excel or Google Sheets
If you prefer desktop tools or already work in spreadsheets, you can convert a JSON file to CSV using Excel or Google Sheets with a small workaround.
3.1 Convert a JSON file to CSV (quick overview)
- Convert the JSON file to CSV with an online converter (upload the
.jsonfile and export.csv). - Open the resulting CSV in Excel or Google Sheets.
- Clean up headers and data types if necessary.
This is the easiest way to convert .json to csv without writing any code.
3.2 Import JSON to Google Sheets and export as CSV
Google Sheets has Apps Script and add-ons that can help:
- Create a new Google Sheet.
- Use an Apps Script or an add-on to fetch JSON from a URL or paste it into a script.
- Write rows into the sheet based on JSON keys.
- Go to File → Download → Comma-separated values (.csv) to convert JSON into CSV and save it locally.
4. Method 3 – Convert JSON to CSV with code
For automation or batch processing, writing a small script is often the best way to convert JSON to CSV. Here is the general idea:
- Read the JSON file (object, array of objects, or JSON Lines).
- Normalize records into a flat structure.
- Write rows and headers to a CSV file.
You can do this in many languages:
- Python – use
json+csvmodules or libraries likepandas. - JavaScript/Node.js – parse JSON and join values with commas.
- Command-line tools – use
jqand other CLI utilities.
This approach is ideal when you need to convert JSON file to CSV regularly, or when you want full control over the conversion rules.
5. Handling nested JSON when converting to CSV
A common challenge when converting JSON to CSV is nested objects and arrays. For example:
{
"user": { "id": 1, "name": "Alice" },
"items": [
{ "sku": "A1", "price": 10 },
{ "sku": "B2", "price": 20 }
]
}
Typical strategies to convert from JSON to CSV in these cases:
- Flatten nested objects into dotted keys, such as
user.id,user.name. - Index array elements like
items[0].sku,items[0].price. - Explode arrays into multiple rows if you need one row per array item.
Many converters offer a “flatten” option to transform JSON to CSV automatically. When using code, you can write a small helper function to walk the JSON tree and produce flat key-value pairs.
6. JSON Lines (NDJSON) to CSV
JSON Lines (also called NDJSON) stores one JSON object per line:
{"id": 1, "name": "Alice"}
{"id": 2, "name": "Bob"}
To change JSON to CSV for JSON Lines:
- Split the text by line.
- Parse each line as a JSON object.
- Combine all keys as headers.
- Write one CSV row per line.
Many online JSON to CSV converters explicitly support JSON Lines and make converting JSON to CSV much easier in log or event data scenarios.
7. Common errors when converting JSON to CSV
When you convert JSON to CSV format, watch out for these common issues:
- Invalid JSON syntax (missing commas or quotes).
- Mixed structures (some records are objects, others are arrays).
- Inconsistent fields across objects.
- Very large files that need streaming or batch processing.
If a tool fails, try:
- Validating the JSON with a formatter.
- Simplifying or splitting the file.
- Writing a custom script tailored to your data shape.
8. Summary
To recap the main ways to convert JSON to CSV:
- Use an online JSON to CSV converter to quickly change JSON to CSV or transform JSON to CSV in one click.
- Use Excel or Google Sheets to open converted CSV files when you need manual editing.
- Write scripts when you want to convert JSON files to CSV in bulk or on a schedule.
Once you pick the best way to convert JSON to CSV for your use case, you can turn raw JSON from APIs, logs, or exports into clean CSV files ready for analysis.