use case
How to convert JSON to CSV in Python
Use the REST API or Python's csv module to convert JSON data to CSV programmatically.
Python scripts that process API responses, database exports, or data pipeline outputs frequently need to write CSV files. The quickhelp.dev JSON-to-CSV REST API lets you convert data without writing the CSV logic yourself — useful in notebooks, automation scripts, and quick data tasks. This guide shows both the API approach and the native Python csv module approach.
Step-by-step guide
- Use the REST API from Python: import requests, json; data = [{"name": "Alice", "age": 30}]; r = requests.post('https://quickhelp.dev/api/json-to-csv', json={'input': json.dumps(data), 'mode': 'json-to-csv', 'delimiter': ',', 'flatten': True}); print(r.json()['output'])
- Or use Python's built-in csv module: import csv, io, json; data = json.loads(open('data.json').read()); buf = io.StringIO(); w = csv.DictWriter(buf, fieldnames=data[0].keys()); w.writeheader(); w.writerows(data); print(buf.getvalue())
- Write the CSV to a file: Replace io.StringIO() with open('output.csv', 'w', newline='') to write directly to disk. Use encoding='utf-8-sig' if the file will be opened in Excel on Windows — the BOM prevents encoding issues with non-ASCII characters.
Frequently asked questions
- Which is faster: the API or Python's csv module?
- Python's built-in csv module is faster for large datasets because there is no network round-trip. Use the API for quick one-off conversions or when you need the flatten option without writing custom code.
- How do I handle pandas DataFrames?
- pandas has built-in JSON and CSV conversion: df = pd.read_json('data.json') then df.to_csv('output.csv', index=False). Use pd.json_normalize(data) if the JSON is nested.
Try it now
Use the JSON to CSV Converter to complete this task — free, no sign-up, runs in your browser.
Open JSON to CSV Converter →