ToolsCourt
BlogHow to Convert JSON to CSV: Complete Guide with Examples
Dev8 min read·January 2025

How to Convert JSON to CSV: Complete Guide with Examples

Flat JSON, nested JSON, JSON arrays — every case covered with browser tools, Python, JavaScript, and command line.

Try the free tool
No signup. Runs in your browser. Takes 10 seconds.
Open JSON to CSV

When Do You Need to Convert JSON to CSV?

JSON is the standard format for APIs and web services. CSV is the standard format for spreadsheets and data analysis. You need to convert JSON to CSV when: (1) you pull data from an API and want to analyse it in Excel or Google Sheets, (2) a client or colleague needs data in a spreadsheet-friendly format, or (3) you are importing data into a system that accepts CSV but not JSON.

Simple Flat JSON — Easiest Case

Input JSON array:
[
  {"name": "Rahul", "age": 28, "city": "Mumbai"},
  {"name": "Priya", "age": 25, "city": "Delhi"}
]

Output CSV:
name,age,city
Rahul,28,Mumbai
Priya,25,Delhi

This case is trivial — headers come from the keys of the first object, values come from corresponding keys in each subsequent object.

Nested JSON — The Tricky Case

Input JSON:
[{"name": "Rahul", "address": {"city": "Mumbai", "pin": "400001"}}]

Naive conversion fails — "address" is an object, not a value.

Flattened correctly with dot-notation:
name, address.city, address.pin
Rahul, Mumbai, 400001

Python: One-Liner Conversion

import json, csv, pandas as pd

# Simple method with pandas
df = pd.json_normalize(json.load(open('data.json')))
df.to_csv('output.csv', index=False)

# Without pandas (built-in only)
data = json.load(open('data.json'))
with open('output.csv', 'w', newline='') as f:
    writer = csv.DictWriter(f, fieldnames=data[0].keys())
    writer.writeheader()
    writer.writerows(data)

JavaScript / Node.js

const data = [
  { name: "Rahul", city: "Mumbai" },
  { name: "Priya", city: "Delhi" }
];

const headers = Object.keys(data[0]);
const csv = [
  headers.join(','),
  ...data.map(row => headers.map(h => `"${row[h]}"`).join(','))
].join('\n');

// In Node.js:
require('fs').writeFileSync('output.csv', csv);
💡 For quick one-off conversions without writing code, use the ToolsCourt JSON to CSV converter. Paste your JSON, get your CSV, download — works with nested objects via dot-notation flattening.
Ready to try it?
Free, instant, no signup required.
Open JSON to CSV Free →