How to Convert a JSON File to CSV
3 methods — browser tool, Python, and Node.js
JSON is the standard format for APIs and web apps, but most spreadsheet tools, databases, and import wizards expect CSV. Converting a JSON array of objects to CSV is straightforward when the JSON is flat — nested objects need a bit more work. Here's how.
Method 1: Using Tabular (no code required)
- 1Go to the JSON to CSV tool on Tabular.
- 2Upload your .json file — it should be a JSON array of objects (e.g. [{...}, {...}]).
- 3Click Run — Tabular converts each object to a CSV row using the object keys as column headers.
- 4Download the .csv file.
Tabular expects a flat JSON array. If your JSON has nested objects or arrays, flatten them first — use the Python method below which handles nested structures.
Method 2: Using Python (pandas)
- 1Install pandas: pip install pandas
- 2Run the script below.
python
import pandas as pd
import json
# Simple flat JSON array
df = pd.read_json("input.json")
df.to_csv("output.csv", index=False)
# If JSON is nested, flatten it first:
# with open("input.json") as f:
# data = json.load(f)
# df = pd.json_normalize(data) # flattens nested keys with dot notation
# df.to_csv("output.csv", index=False)pd.json_normalize() flattens nested objects into dot-notation columns (e.g. 'address.city'). This is usually the best approach for API response data.
Method 3: Using Node.js
- 1No extra packages needed — uses built-in modules.
- 2Run the script below.
javascript
const fs = require("fs");
const data = JSON.parse(fs.readFileSync("input.json", "utf8"));
if (!Array.isArray(data) || data.length === 0) {
console.error("Expected a non-empty JSON array");
process.exit(1);
}
const headers = Object.keys(data[0]);
const rows = data.map((row) =>
headers.map((h) => JSON.stringify(row[h] ?? "")).join(",")
);
const csv = [headers.join(","), ...rows].join("\n");
fs.writeFileSync("output.csv", csv);
console.log(`Converted ${data.length} records to CSV`);Frequently asked questions
What JSON structure can be converted to CSV?
CSV conversion works best with a flat JSON array of objects where every object has the same keys — for example: [{"name": "Alice", "email": "alice@example.com"}, ...]. Nested objects, arrays-of-arrays, and deeply nested structures need to be flattened first.
How do I convert nested JSON to CSV?
Use Python's pd.json_normalize() which automatically flattens one level of nesting using dot notation. For example, {"address": {"city": "Austin"}} becomes a column named 'address.city'. For deeply nested data, you may need to write custom flattening logic.
What if different JSON objects have different keys?
pandas handles this automatically — columns will be created for all keys found across all objects, and missing values will be filled with NaN (blank in the CSV). The Node.js script above uses the first object's keys, so it would miss keys that only appear in later objects.
Can I convert CSV back to JSON?
Yes. Use Tabular's CSV to JSON tool — upload your CSV and download a JSON array. In Python: pd.read_csv('input.csv').to_json('output.json', orient='records', indent=2).
Ready to try the fastest method?
Upload a JSON file (array of objects) and convert it to a clean CSV instantly. Free, no signup required.
JSON → CSV — free
Papiral
Tabular