NativeOffice for Windows NativeOffice Mobile NativeOffice Scan NativeOffice Web ↗ Pinwheel
Premium Developers Blog Q&A Sign in Get NativeOffice
Back to all posts

How to Convert Excel to JSON in Python (pandas, 3 Lines)

To convert Excel to JSON in Python, install pandas and openpyxl (pip install pandas openpyxl), load the file with pd.read_excel("data.xlsx"), and save it with df.to_json("data.json", orient="records", indent=2). That gives you a JSON array with one object per row, keyed by your header row. The rest of this guide covers multiple sheets, dates, empty cells and merged headers.

How do I convert Excel to JSON with pandas?

The most common way to do this is with the pandas library, which handles the heavy lifting of reading spreadsheet data and converting it into a clean JSON structure.

import pandas as pd

df = pd.read_excel("data.xlsx")
df.to_json("data.json", orient="records", indent=2)

That's it for a basic conversion. pandas.read_excel() loads your spreadsheet into a DataFrame, and to_json() writes it back out as JSON. The orient="records" part matters, it produces a list of objects, one per row, which is usually what you actually want when working with JSON in most applications.

How do I convert every sheet in a workbook to JSON?

If your Excel file has more than one sheet, you'll want to be explicit about which one you're reading, or loop through all of them.

import pandas as pd

sheets = pd.read_excel("data.xlsx", sheet_name=None)

for name, df in sheets.items():
    df.to_json(f"{name}.json", orient="records", indent=2)

This reads every sheet into a dictionary of DataFrames and writes each one out as its own JSON file, named after the sheet.

Why are my dates numbers and my empty cells NaN?

Dates turning into strange numbers. Excel stores dates as serial numbers internally, and pandas sometimes carries that quirk into your JSON output. If you see numbers where dates should be, convert the column explicitly before exporting:

df["date_column"] = pd.to_datetime(df["date_column"]).dt.strftime("%Y-%m-%d")

NaN values breaking your JSON. Empty cells become NaN in pandas, which isn't valid JSON. Clean them up first:

df = df.fillna("")

Nested or merged cells not converting cleanly. Pandas expects a flat, tabular structure. If your Excel file has merged cells or multi-row headers, you'll likely need to clean the sheet up first, or handle the header row manually with the header parameter in read_excel().

Can I convert Excel to JSON without writing code?

Not everyone converting Excel to JSON wants to open a Python environment for a one-off task. If you just need to convert a sheet occasionally, without setting up pandas or writing a script, NativeOffice has this built directly into its spreadsheet tool: paste or open your data, and export straight to JSON with a couple of clicks, no code, no dependencies, and it runs entirely offline so your data never leaves your machine. It also works the other way, paste in JSON or YAML and it flattens into a clean spreadsheet table instantly.

Whether you reach for a script or a tool depends on whether this is a one-time task or something you'll be doing repeatedly as part of a pipeline. For the latter, the Python approach above is worth keeping in your toolkit.

For a no-code walkthrough, see how to convert Excel to JSON without code. Going the other way, see how to turn JSON into a spreadsheet table, and for loading sheets into Python, see spreadsheet to pandas.

Frequently asked questions

What does orient="records" do?

It writes a list of objects, one per row, such as [{"name": "A", "qty": 2}]. Without it, pandas uses orient="columns", which nests every value under its column name and is harder to use in most apps.

Do I need openpyxl to read .xlsx files?

Yes. pandas reads .xlsx files through openpyxl, so if you see "Missing optional dependency 'openpyxl'", run pip install openpyxl. Old .xls files need the xlrd package instead.

How do I keep non-English characters readable in the JSON?

Pass force_ascii=False to to_json, so characters like é or हिंदी are written as they are instead of as \u escape codes.

Can I convert Excel to JSON without Python?

Yes. NativeOffice can export a sheet straight to JSON offline, with no code and no upload.