Most guides focus on converting JSON to Excel, but the reverse is equally common. You might have a spreadsheet of product data that needs to be loaded into a web app, a list of configuration values to import into a system, or historical data to upload to a database via API.
This guide covers four practical methods to convert Excel to JSON.
What the Output Looks Like
When converting an Excel spreadsheet to JSON, the standard output is an array of objects where:
- Each row becomes a JSON object
- The first row (header) becomes the keys
- All rows are collected in a JSON array
Given a spreadsheet with columns Product, Price, InStock:
[
{ "Product": "Widget A", "Price": 9.99, "InStock": true },
{ "Product": "Widget B", "Price": 14.50, "InStock": false }
]Method 1: Online Excel to JSON Converters
For a quick conversion, several online tools handle .xlsx files directly. Upload your file, select the sheet if there are multiple, and download the JSON.
Considerations when using online tools:
- Avoid uploading files containing sensitive or confidential data to public websites
- Verify the output handles your Excel data types correctly (dates are a common problem)
- Large files (over 10MB) may time out or be rejected
Method 2: Python with pandas and openpyxl
This is the most reliable and flexible method for most use cases:
pip install pandas openpyxlimport pandas as pd
import json
# Read the Excel file
df = pd.read_excel('data.xlsx', sheet_name='Sheet1')
# Convert to JSON
result = df.to_json(orient='records', indent=2)
# Save to file
with open('output.json', 'w') as f:
f.write(result)
print(f"Converted {len(df)} rows")Reading Multiple Sheets
If your workbook has multiple sheets and you need to convert all of them:
import pandas as pd
import json
# Read all sheets
excel_data = pd.read_excel('data.xlsx', sheet_name=None)
# Convert each sheet
output = {}
for sheet_name, df in excel_data.items():
output[sheet_name] = json.loads(df.to_json(orient='records'))
with open('output.json', 'w') as f:
json.dump(output, f, indent=2)Handling Dates
Dates are the trickiest part of Excel-to-JSON conversion. Excel stores dates as serial numbers internally. pandas reads them as Timestamp objects, which do not serialize to JSON by default. Use a custom serializer:
import pandas as pd
import json
from datetime import date, datetime
def json_serializer(obj):
if isinstance(obj, (date, datetime)):
return obj.isoformat()
raise TypeError(f"Object of type {type(obj)} is not JSON serializable")
df = pd.read_excel('data.xlsx')
records = df.to_dict(orient='records')
with open('output.json', 'w') as f:
json.dump(records, f, default=json_serializer, indent=2)Method 3: JavaScript with SheetJS (xlsx)
SheetJS (also called xlsx) is the most popular JavaScript library for reading Excel files. It works in both Node.js and browsers.
npm install xlsxconst XLSX = require('xlsx');
// Read the workbook
const workbook = XLSX.readFile('data.xlsx');
// Get the first sheet
const sheetName = workbook.SheetNames[0];
const sheet = workbook.Sheets[sheetName];
// Convert to JSON
const records = XLSX.utils.sheet_to_json(sheet);
// Write to file
const fs = require('fs');
fs.writeFileSync('output.json', JSON.stringify(records, null, 2));
console.log(`Converted ${records.length} rows`);SheetJS in the Browser
SheetJS also works client-side — users can select an Excel file and the page converts it to JSON without any server upload:
// Handle file input change
document.getElementById('fileInput').addEventListener('change', function(e) {
const file = e.target.files[0];
const reader = new FileReader();
reader.onload = function(e) {
const data = new Uint8Array(e.target.result);
const workbook = XLSX.read(data, { type: 'array' });
const sheet = workbook.Sheets[workbook.SheetNames[0]];
const json = XLSX.utils.sheet_to_json(sheet);
console.log(json);
};
reader.readAsArrayBuffer(file);
});Method 4: Excel Power Query Export
If you prefer to stay within Excel, you can use Power Query and a small macro to export data as JSON. However, Excel does not natively export to JSON — this requires VBA or Power Automate. For most users, the Python or SheetJS approach is simpler.
Common Issues and Solutions
| Issue | Cause | Solution |
|---|---|---|
| Dates appear as numbers | Excel stores dates as serial integers | Use a date parser or date_format option |
| NaN values in output | Empty cells in pandas become NaN | Use df.fillna('') or df.where(df.notna(), None) |
| Merged cells cause errors | Merged cells have no value in most rows | Unmerge cells in Excel before converting |
| Wrong sheet used | Converter uses the first sheet by default | Specify sheet_name='YourSheet' explicitly |
Need JSON to Excel Instead?
Our free tool converts JSON files back to Excel spreadsheets — handles nested structures automatically.
Convert JSON to Excel Now →