JSON to CSV for Excel — opens clean first time
A CSV that opens cleanly in Excel needs the right delimiter and the right encoding. You pick both here, and there is code at the bottom if you would rather build the file yourself.
Writing the file from Python
Two options: a CSV that Excel opens by double-clicking, or a real .xlsx workbook with the column types already set. The second one is more work but it stops Excel from rewriting your values behind your back.
import csv
import json
with open("data.json", encoding="utf-8") as f:
rows = json.load(f)
# utf-8-sig writes the BOM that makes Excel read UTF-8 correctly on Windows.
fieldnames = list(dict.fromkeys(k for row in rows for k in row))
with open("data.csv", "w", newline="", encoding="utf-8-sig") as f:
writer = csv.DictWriter(f, fieldnames=fieldnames, restval="")
writer.writeheader()
writer.writerows(rows)
Option 1 - a CSV that Excel opens cleanly (UTF-8 with a BOM)
import json
from openpyxl import Workbook
from openpyxl.styles import Font
with open("data.json", encoding="utf-8") as f:
rows = json.load(f)
wb = Workbook()
ws = wb.active
ws.title = "data"
headers = list(dict.fromkeys(k for row in rows for k in row))
ws.append(headers)
for cell in ws[1]:
cell.font = Font(bold=True)
for row in rows:
ws.append([row.get(h, "") for h in headers])
# Keep identifiers like "007" and long account numbers as text.
for row in ws.iter_rows(min_row=2, min_col=1):
for cell in row:
if isinstance(cell.value, str) and cell.value.isdigit():
cell.number_format = "@"
wb.save("data.xlsx")
Option 2 - a real .xlsx workbook with the column types set
The utf-8-sig encoding in option 1 is the whole trick for Excel on Windows: it writes the three-byte byte order mark that tells Excel the file is UTF-8 instead of the local code page. Without it, a name like "Zoë" arrives as "Zoë".
Option 2 is worth the extra dependency when the file has to be handed to someone who will edit it - the number formats are set once, so nobody has to fix the columns by hand.
A worked example
A JSON payload with a character Excel gets wrong, and a column Excel would rewrite.
customers.json
[
{ "name": "Zoë Müller", "postcode": "01234", "id": 1000000000000001 }
]
customers.csv
name,postcode,id
Zoë Müller,01234,1000000000000001
The converter above defaults to a tab delimiter so the file pastes straight into Excel - switch it to comma in the settings to match this example. Written as plain UTF-8, Excel on Windows shows "Zoë Müller". The file above is written as utf-8-sig, so it shows "Zoë Müller". The second problem - Excel turning 01234 into the number 1234 and 1000000000000001 into scientific notation - is a display setting on import, which the guide below explains.
Get a CSV that opens cleanly
Three settings, in the order that matters.
-
Paste the JSON
The converter above parses it in your browser and shows the table immediately.
-
Choose the delimiter
Tab is the default because it pastes into Excel cleanly. Switch to comma for a file other programs will read.
-
Download and open
Double-clicking the file opens it in Excel with the columns where you expect them.
-
Fix the columns Excel rewrote
If a postcode or an account number came out as a number, import the file with Data > From Text and set that column to Text.
The Excel details that catch people out
Three settings decide whether the file opens cleanly or wastes an afternoon.
Encoding is right
The download is UTF-8, so accented characters and emoji survive the round trip on every platform.
Delimiters are explicit
Tab or comma, chosen by you rather than guessed from the data, so a value containing a comma cannot break the row.
Column order is preserved
The header order follows the JSON, so the sheet matches the API response instead of being re-sorted by the browser.
Straight to a real workbook
If you want a .xlsx rather than a CSV, the JSON to Excel converter produces a genuine workbook in your browser.
The full JSON to CSV guide
Delimiters, quoting, encoding and the spreadsheet edge cases, explained properly.
Related tools: JSON to Excel converter · JSON to CSV in Python · CSV to JSON converter · JSON to Markdown
Frequently asked questions
Encoding, delimiters and the columns Excel keeps rewriting.
How do I open the CSV in Excel?
Why do my accented characters look wrong in Excel?
utf-8-sig adds a byte order mark that tells Excel the file is UTF-8. The Python snippet above uses that encoding.How do I stop Excel from reformatting my IDs?
Should I use tabs or commas?
Can I get a real .xlsx file?
Get an Excel-ready CSV
Free, instant, and private — your JSON never leaves this tab.