Converting JSON to CSV is one of the most common tasks in data work. JSON is the default format for APIs and modern applications. CSV is what spreadsheets, databases and analysts expect. This guide covers every way to do the conversion — with code and without.
Why convert JSON to CSV?
- Spreadsheet analysis — Excel and Google Sheets work natively with CSV, not JSON
- Database imports — most database import tools accept CSV more easily than JSON
- Data sharing — CSV is universally readable without any special tools
- Legacy system compatibility — older systems often only accept flat CSV files
Method 1: Convert JSON to CSV using Python
If your JSON is an array of objects (the most common API response format), Python's built-in csv and json modules handle the conversion cleanly:
import json
import csv
# Load JSON
with open('data.json', 'r') as f:
data = json.load(f)
# Write CSV
if data:
with open('output.csv', 'w', newline='') as f:
writer = csv.DictWriter(f, fieldnames=data[0].keys())
writer.writeheader()
writer.writerows(data)
print(f"Converted {len(data)} records to CSV")
Method 2: Convert JSON to CSV using pandas
Pandas is more powerful — it handles nested structures and gives you more control:
import pandas as pd
# Read JSON file or JSON string
df = pd.read_json('data.json')
# Flatten nested objects if needed
# df = pd.json_normalize(data) # for deeply nested JSON
# Save as CSV
df.to_csv('output.csv', index=False)
print(df.shape) # (rows, columns)
💡 Nested JSON tip: If your JSON has nested objects like {"user": {"name": "Alice", "email": "alice@example.com"}}, use pd.json_normalize() to flatten it into flat columns like user.name and user.email.
Method 3: Convert JSON to CSV without code
If you just need a one-off conversion without writing any Python, Sylvaera's free Data Format Converter handles it in three clicks:
- Paste your JSON or upload a .json file
- Select JSON as input and CSV as output
- Click Convert and download your CSV instantly
It also supports JSON → Excel, JSON → YAML and JSON → XML in the same tool.
What if my JSON is not an array?
CSV is inherently flat — each row is a record. If your JSON is a single object (not an array), it becomes a single-row CSV. If it's a deeply nested tree structure, you need to decide how to flatten it first.
Common strategies:
- Dot notation flattening —
user.address.citybecomes a column nameduser.address.city - Pick specific fields — extract only the fields you care about into a flat structure before converting
- Explode arrays — if a JSON field contains an array, decide whether to create one row per array element or join them into a single comma-separated string
JSON to Excel conversion
Converting JSON directly to Excel (.xlsx) preserves data types better than CSV — numbers stay numeric, dates stay dates, booleans stay booleans. In Python:
import pandas as pd
df = pd.read_json('data.json')
df.to_excel('output.xlsx', index=False, engine='openpyxl')
print("Saved as Excel")
JSON to YAML conversion
YAML is popular for configuration files and Kubernetes manifests. Converting JSON to YAML makes configs more human-readable:
import json
import yaml
with open('config.json') as f:
data = json.load(f)
with open('config.yaml', 'w') as f:
yaml.dump(data, f, allow_unicode=True, default_flow_style=False)
print("Converted to YAML")
The fastest way to convert between JSON, CSV, YAML, XML and Excel is Sylvaera's free Data Format Converter — no code, no sign-up, instant download.
Try Data Format Converter — Free
Convert JSON to CSV, Excel, YAML or XML instantly. Paste or upload your data, select formats, download in one click. Zero AI cost — pure instant conversion.
Open Data Format Converter →