How to Convert JSON to CSV (and CSV to JSON)
JSON and CSV are the two most common data formats, and converting between them is a daily task for developers, analysts, and content teams. JSON is structured and nested; CSV is flat and tabular. Converting between them requires flattening nested objects and handling arrays โ which is where most manual approaches break down.
- Convert between JSON and CSV formats.
- Covers json to csv conversion.
- Covers csv to json conversion.
- Covers handling edge cases.
- Covers programmatic conversion.
JSON to CSV Conversion
A flat JSON array converts directly to CSV โ each object becomes a row, each key becomes a column header:
[{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}]
becomes:
name,age
Alice,30
Bob,25
Nested objects require flattening: {"user": {"name": "Alice"}} becomes user.name as the column header. Arrays are typically joined with a delimiter or split into multiple rows. The JSON-CSV Converter handles nested objects and arrays automatically.
CSV to JSON Conversion
CSV to JSON is the reverse: each row becomes an object, each header becomes a key. The first row is treated as headers by default:
name,age,city
Alice,30,NYC
becomes:
[{"name": "Alice", "age": "30", "city": "NYC"}]
Note that CSV has no type information โ all values come in as strings. Numbers, booleans, and null values need to be parsed into their proper types after conversion.
Handling Edge Cases
Commas inside values require quoting: "New York, NY" wraps the value in double quotes. Newlines inside values also require quoting. Double quotes inside quoted values are escaped by doubling: "She said ""hello""" represents the text She said "hello". Missing values in rows produce empty strings or null. The JSON-CSV Converter handles all of these edge cases โ paste messy CSV and get clean JSON output.
background-size animation or @property registered custom properties instead.Programmatic Conversion
In JavaScript, use the Papaparse library for CSV parsing: Papa.parse(csvString, {header: true}) returns an array of objects. For JSON to CSV: Papa.unparse(jsonArray). In Python, the csv and json standard library modules handle both directions. pandas makes it even simpler: pd.read_csv('file.csv').to_json() and pd.read_json('file.json').to_csv(). For quick one-off conversions without code, the JSON-CSV Converter handles files up to 10MB in your browser.