JSON to CSV/ JSON Array → CSV File
Convert JSON arrays to CSV — custom delimiters (comma/semicolon/tab), nested object flattening, and direct .csv download.
Delimiter
JSON
CSV
Did this tool solve your problem?
Code Examples
JavaScript / Node.js
// Using json2csv npm package
import { Parser } from 'json2csv';
const data = [
{ name: 'Alice', age: 30, city: 'Beijing' },
{ name: 'Bob', age: 25, city: 'Shanghai' },
];
const parser = new Parser({ fields: ['name', 'age', 'city'] });
const csv = parser.parse(data);
// name,age,city
// Alice,30,Beijing
// Bob,25,Shanghai
// Built-in (no deps)
const toCsv = (arr) => {
const keys = Object.keys(arr[0]);
const rows = arr.map(r => keys.map(k =>
JSON.stringify(r[k] ?? '')).join(','));
return [keys.join(','), ...rows].join('\n');
};Python (pandas)
import pandas as pd
import json
# From JSON string
json_str = '[{"name":"Alice","age":30},{"name":"Bob","age":25}]'
df = pd.read_json(json_str)
df.to_csv('output.csv', index=False)
# From nested JSON (flatten)
from pandas import json_normalize
data = [{"user": {"name": "Alice"}, "score": 100}]
df = json_normalize(data)
# Columns: user.name, score
df.to_csv('flat.csv', index=False)
# Custom delimiter
df.to_csv('output.csv', sep=';', index=False)Go
import (
"encoding/csv"
"encoding/json"
"os"
)
type Row struct {
Name string `json:"name"`
Age int `json:"age"`
}
func main() {
data := []Row{{"Alice", 30}, {"Bob", 25}}
f, _ := os.Create("output.csv")
w := csv.NewWriter(f)
w.Write([]string{"name", "age"})
for _, r := range data {
w.Write([]string{r.Name, fmt.Sprint(r.Age)})
}
w.Flush()
}Shell (jq + awk)
# jq: extract fields as TSV cat data.json | jq -r ' .[] | [.name, .age, .city] | @tsv ' > output.tsv # With headers cat data.json | jq -r ' ["name","age","city"], (.[] | [.name, .age, .city]) | @csv ' > output.csv # Using Miller (mlr) mlr --json --ocsv cat data.json > output.csv
Frequently Asked Questions
What are common use cases for JSON to CSV?
JSON is the standard API data format; CSV is the format for spreadsheets (Excel, Google Sheets) and data analysis tools (pandas, R). Common use cases: exporting API data to Excel, importing database query results into data pipelines, preparing bulk import files for e-commerce platforms or CRMs.
How are nested JSON objects handled?
Two approaches: 1) Flatten — {"user": {"name": "Alice", "age": 30}} becomes two columns user.name and user.age. 2) Serialize — the nested object is JSON-stringified into a single cell. This tool's "Flatten nested objects" option uses dot-notation keys.
How are special characters in CSV handled?
RFC 4180 requires: fields containing commas, newlines, or double quotes must be wrapped in double quotes; double quotes inside fields are escaped by doubling them (""). This tool handles these cases automatically.
When should I use semicolons instead of commas?
In some European countries (Germany, France, Netherlands), commas serve as decimal separators, so Excel there defaults to semicolons (;) as CSV delimiters. Use semicolons when the file will be opened in European Excel.
How do I convert JSON to CSV in Python?
Using stdlib: import json, csv; data = json.load(open('data.json')); writer = csv.DictWriter(open('out.csv', 'w'), fieldnames=data[0].keys()); writer.writeheader(); writer.writerows(data). With pandas: pd.read_json('data.json').to_csv('out.csv', index=False).
Can formats other than JSON arrays be converted?
Supported: JSON arrays (most common), a single JSON object (one output row), an object containing an array field (the first array is extracted). Not supported: deeply nested arrays, highly irregular arrays.