How-to Guides Data & Encoding

How to Convert JSON to CSV and Back

Turn an API response into a spreadsheet-ready CSV and a CSV back into JSON, with notes on how columns, nested values and data types are handled.

Last reviewed:

AdSense Placeholder
Slot: header_reference_page
On this page

Steps

  1. Check that the JSON is valid

    Paste it into the JSON Formatter & Prettifier or JSON Validator & Online Debugger first. A missing comma or quote is the most common reason a conversion fails.

  2. Convert JSON to CSV

    Paste a JSON array of objects into the JSON to CSV Converter and convert. The header row is the union of keys across all objects, in the order first seen, and a missing field becomes an empty cell.

  3. Inspect the CSV

    For example, [{"id":1,"name":"Ana","tags":["a","b"]},{"id":2,"name":"Ben","city":"Lyon"}] becomes a table with the columns id,name,tags,city. The array in tags is stored as the text ["a","b"], and Ben's tags cell is empty.

  4. Convert CSV back to JSON

    Paste the CSV into the CSV to JSON Converter. The first row becomes the keys and every following row becomes an object. Every value is a string, and a short row is padded with empty strings.

  5. Validate the shape of the result

    If the JSON will feed an API or database, describe what it should look like and check it with the JSON Schema Validator. That catches missing fields and values that should be numbers.

  6. Open the CSV in a spreadsheet and spot-check

    Import the file as UTF-8 text and compare a few rows with the source. Watch for IDs with leading zeros and long numbers that a spreadsheet may reformat when it opens the file.

What you need

JSON that is an array of objects (one object per row) or a CSV with a header row. Both converters run locally, so you can use real data.

What the conversion does

Converting this JSON:

[{"id":1,"name":"Ana","tags":["a","b"]},{"id":2,"name":"Ben","city":"Lyon"}]

gives this CSV:

id,name,tags,city
1,Ana,"[""a"",""b""]",
2,Ben,,Lyon

and converting that CSV back gives:

[{"id": "1", "name": "Ana", "tags": "[\"a\",\"b\"]", "city": ""}, {"id": "2", "name": "Ben", "tags": "", "city": "Lyon"}]

Note what changed on the round trip: id is now the string "1", the tags array is now a string, and Ben's missing tags and Ana's missing city became empty strings. The round trip preserves the table, not the types.

Rules of thumb

Situation What happens
Objects have different keys Columns are the union of all keys, first-seen order
A value is null or absent The cell is empty
A value is a nested object or array Stored in the cell as compact JSON text
A field contains a comma, quote or line break The cell is quoted so the CSV stays valid
CSV row shorter than the header Missing values become empty strings

Common pitfalls

  • Expecting types to survive. CSV is text. Convert numbers and booleans after reading it back.
  • Flat versus nested. If you need real nested structure, keep JSON as the source of truth and export CSV only for reporting.
  • Spreadsheets mangling values. Excel may drop leading zeros, turn long numbers into scientific notation or reinterpret text that looks like a date.
  • Using TSV by mistake. If your data contains tabs or you pasted from a spreadsheet, use the tab-separated variants instead.

Going further

For how JSON itself is structured, see How JSON Works; for a side-by-side with other formats, see JSON vs YAML vs XML.

Try these tools

See also

  • Guide How JSON Works
    The six JSON value types, why parsing fails, traps with big integers and key order, JSONPath queries and converting JSON to TypeScript.
  • Comparison JSON vs YAML vs XML
    JSON for APIs and data exchange, YAML for hand-edited configuration, XML for documents and schema-heavy standards.
  • Glossary JSON
    JSON (JavaScript Object Notation) is a lightweight text format for structured data, built from objects, arrays, strings, numbers, true.
  • Glossary CSV
    CSV (comma-separated values) is a plain-text format for tables, with one row per line and values separated by commas.

Frequently Asked Questions

CSV has no data types, so converting a CSV to JSON produces string values: "1" rather than 1. Convert the fields you need to numbers or booleans in your code, or check them with a schema.

A CSV cell holds one value, so a nested object or array is written into the cell as compact JSON text. Converting back gives you that text as a string, not the original structure.

No. Both converters run in your browser, so the data never leaves your device.

AdSense Placeholder
Slot: footer_leaderboard