How to Convert JSON to CSV (Free Online, Python, and Excel)

To convert JSON to CSV, turn each JSON object into one row of a spreadsheet and each key into a column heading. The fastest way is an online converter: paste your JSON, and download the CSV. If you do this often, Python or jq will do the same job from a script. This guide covers all three routes, plus the one thing that trips most people up — nested objects.

CSV is a flat grid of rows and columns. JSON is a tree that can hold objects inside objects and lists inside objects. Converting is mostly straightforward when your JSON is a simple list of flat objects. It gets interesting when the data is nested, because a flat grid has nowhere to put a second level. Every method below deals with that in some way.

Rows of data in a spreadsheet on a desk

JSON to CSV Online in 30 Seconds

If you have one file to convert and you want it done now, use the free JSON to CSV converter. Paste your JSON (or upload the file), and the tool turns it into a CSV you can download and open in Excel or Google Sheets. Nested objects are flattened into dotted column names like address.city, so nothing is silently dropped.

The online route is the right choice when you are converting API responses, exported app data, or a config file by hand. It is the wrong choice when the conversion needs to happen every day at 3am — that is a job for a script, covered below.

One thing to check before you convert: is your JSON an array of objects, or a single object? Most converters expect an array like this:

[
  {"id": 1, "name": "Aisha", "city": "Lahore"},
  {"id": 2, "name": "Ben", "city": "Leeds"},
  {"id": 3, "name": "Carmen", "city": "Lima"}
]

If your data is a single object with an array buried inside it — an API response that looks like {"results": [...], "total": 3} — pull out the array first. In the online tool, paste just the array. In Python, load the JSON and pass data["results"] to the writer instead of data.

How JSON Maps to CSV Rows and Columns

The mapping has three rules, and once you see them the whole conversion makes sense:

  • Each object becomes one row. Three objects in your array means three rows in your CSV, plus a header row.
  • Each key becomes one column. The keys id, name, and city become three column headings.
  • Each value becomes one cell. Numbers, strings, and booleans drop straight into cells.

The example above becomes:

id,name,city
1,Aisha,Lahore
2,Ben,Leeds
3,Carmen,Lima

Two details matter here. First, the header row is built from the union of all keys across every object. If one object is missing a key, its cell is left empty — the row does not shift sideways. Second, CSV has no data types. The number 1, the string "1", and the boolean true all become plain text in the file. Excel will guess types when it opens the file, which is usually fine but can mangle things like leading zeros in postcodes — more on that below.

What about values that contain commas, quotes, or line breaks? CSV handles them with a quoting rule from RFC 4180: a field containing the delimiter, a double quote, or a line break is wrapped in double quotes, and any quote inside it is written twice. So the name Say "hi", please becomes "Say ""hi"", please" in the file. Every decent converter and library applies this automatically. If you ever build CSV by joining strings with commas by hand, you will get this wrong — use a real CSV writer.

JSON code displayed on a computer monitor

The Nested Object Problem (and How Flattening Works)

Real JSON is rarely flat. A typical API record looks like this:

{
  "id": 1,
  "name": "Aisha",
  "address": {"city": "Lahore", "postcode": "54000"},
  "tags": ["vip", "newsletter"]
}

A CSV row has no room for an object inside a cell. There are two standard answers, and you should pick deliberately rather than letting a tool pick for you.

Flattening is the usual choice. Each nested key becomes its own column, with the path joined by dots: address.city and address.postcode. The row stays one row, and every value stays searchable and sortable in a spreadsheet. This is what pandas json_normalize does by default, and what most online converters do.

Stringifying keeps the nested object as JSON text inside a single cell: the address column holds {"city": "Lahore", "postcode": "54000"}. The data survives the round trip, but you cannot sort or filter by city in Excel. Use this only when you plan to convert back to JSON later.

Arrays need a decision too. You have three options: join the values into one cell (vip; newsletter), explode them into extra rows (one row per tag, with the rest of the record repeated), or keep them as JSON text. Joining is fine for display; exploding is the right call when each array item deserves its own row for analysis, as with order line items. There is no single correct answer — it depends on what you will do with the CSV next.

Convert JSON to CSV in Python

Python’s standard library handles flat JSON with no extra installs. The json module loads the data, and csv.DictWriter writes it. One detail matters: open the output file with newline="", as the csv module docs recommend, or you get a blank line between every row on Windows.

import csv, json

with open("data.json") as f:
    rows = json.load(f)

with open("output.csv", "w", newline="") as f:
    writer = csv.DictWriter(f, fieldnames=rows[0].keys())
    writer.writeheader()
    writer.writerows(rows)

This works when every object has the same keys. If some objects have extra keys, build the header from every key seen in any row instead of just the first row:

columns = list(dict.fromkeys(key for row in rows for key in row))

For nested JSON, pandas does the flattening for you in one call. json_normalize turns nested objects into dotted columns automatically:

import pandas as pd

df = pd.json_normalize(data)
df.to_csv("output.csv", index=False)

The index=False argument stops pandas adding an extra column of row numbers to your CSV. If your data has an array of objects you want as rows — say, each customer has a list of orders — json_normalize takes a record_path argument to explode that array into rows and a meta argument to carry parent fields down onto each row.

Which should you use? The standard library is enough for flat data and small scripts. Reach for pandas when the JSON is nested, the file is large, or you want to filter and clean the data before writing it out.

Person reviewing printed data and spreadsheets

Convert JSON to CSV With jq (Command Line)

If you live in a terminal, jq is the fastest way to convert JSON to CSV. It has a built-in @csv filter that takes an array and writes it as one CSV line, handling the quoting for you. Always pair it with the -r flag for raw output, or jq wraps the whole line in JSON quotes.

To pull specific fields:

jq -r '.[] | [.id, .name, .email] | @csv' data.json

To convert every field with a header row, take the keys from the first object:

jq -r '(.[0] | keys_unsorted) as $k | $k, (.[] | [.[$k[]]]) | @csv' data.json > data.csv

jq does not flatten nested objects automatically. For nested data, name each path explicitly in the array, like .address.city. That is more typing, but it means you choose exactly which columns appear and in what order — handy when the CSV feeds another system that expects a fixed layout.

One more jq tip: if your file is NDJSON (one JSON object per line, common in logs and data exports), add the -s slurp flag or use inputs so jq reads the whole stream instead of choking on the first line.

Open the Result in Excel or Google Sheets

A CSV file opens in Excel with a double-click, but the plain double-click route has two traps. First, Excel guesses the encoding, and non-English characters can come out garbled if the file is UTF-8 without a byte-order mark. Second, Excel guesses types: a postcode like 01234 loses its leading zero, and a long ID like 123456789012345678 gets rounded.

The safer route in Excel is Power Query: go to Data → Get Data → From File → From Text/CSV, pick your file, and use the preview to set column types before loading. For JSON files you can skip the conversion entirely — Data → Get Data → From File → From JSON opens the Power Query editor, where you convert the record to a table and expand the columns you need.

In Google Sheets, use File → Import → Upload, choose the CSV, and pick “Replace current sheet” with comma as the separator. Sheets keeps leading zeros if the column is treated as text, and its import dialog lets you check the result before committing.

Lines of code on a laptop screen

Going the other way — you have a CSV and need JSON — the CSV to JSON converter does the reverse conversion in the browser. The two tools pair well when you are shuttling data between a spreadsheet and an API.

Frequently Asked Questions

Can I convert JSON to CSV without installing anything?

Yes. Paste your JSON into the free JSON to CSV converter and download the CSV. It runs in your browser, so there is nothing to install on Windows, Mac, or Linux.

How do I convert nested JSON to CSV?

Flatten it. Each nested key becomes its own column with a dotted name, so {"address": {"city": "Lahore"}} becomes a column called address.city. In Python, pandas.json_normalize does this in one call. Online converters do it automatically.

Why does my CSV have blank lines between rows?

On Windows, Python’s csv module writes an extra blank line after each row unless you open the file with newline="". Open the output file as open("output.csv", "w", newline="") and the blank lines disappear.

Does converting JSON to CSV lose data?

It can. CSV has no data types, so numbers, booleans, and nulls all become text, and nested structure is either flattened or stringified. If you need a perfect round trip back to JSON, keep the original file — CSV is a one-way export for analysis, not a backup format.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top