E-commerce APIs typically return order data as JSON, while operations teams often use Excel to filter orders, calculate totals, and update shipping statuses. To move the same data between these workflows, you can export the JSON to Excel, edit the worksheet, and then convert it back to JSON.

This tutorial uses the same set of orders to demonstrate both conversions. Python’s built-in json module reads and writes the JSON files, and Free Spire.XLS for Python handles the Excel workbook.

1. Install the Dependency and Prepare the JSON File

Run the following command in your terminal.

pip install spire.xls.free 

Save the following sample data in a file named orders.json.

[ { "order_id": "000147", "order_date": "2026-11-03", "product": "Wireless Mouse", "quantity": 3, "status": "Shipped" }, { "order_id": "000148", "order_date": "2026-11-04", "product": "Mechanical Keyboard", "quantity": 2, "status": "Awaiting Shipment" }, { "order_id": "000149", "order_date": "2026-11-05", "product": "USB-C Docking Station", "quantity": 5, "status": "Delivered" } ] 

The file contains a JSON array. Each object maps to a row in Excel, and each field maps to a column. Fields such as the order ID, date, and product name are stored as text. Storing the order ID as text preserves its leading zeros. The quantity field is written as a number so you can sum and sort quantities in Excel.

2. Convert JSON to Excel Using Python

Use json.load() to read the list of orders, then write the data to a worksheet in a fixed column order. This keeps the worksheet layout consistent even if the fields appear in a different order in the JSON objects.

import json from spire.xls import FileFormat, Workbook input_path = "orders.json" output_path = "orders.xlsx" headers = ("order_id", "order_date", "product", "quantity", "status") with open(input_path, encoding="utf-8") as file: orders = json.load(file) workbook = Workbook() try: workbook.CreateEmptySheets(1) sheet = workbook.Worksheets[0] sheet.Name = "Orders" # Write the column headers for col, header in enumerate(headers, start=1): cell = sheet.Range[1, col] cell.Text = header cell.Style.Font.IsBold = True # Write the orders starting from the second row for row, order in enumerate(orders, start=2): for col, field in enumerate(headers, start=1): cell = sheet.Range[row, col] if field == "quantity": cell.NumberValue = order[field] else: cell.Text = order[field] for col in range(1, len(headers) + 1): sheet.AutoFitColumn(col) workbook.SaveToFile(output_path, FileFormat.Version2016) finally: workbook.Dispose() 

Running the script creates orders.xlsx. The Orders worksheet contains one header row and three order rows. When you open the workbook, the first order ID still appears as 000147, and you can use the quantity 3 directly in calculations. Dates are stored as text in YYYY-MM-DD format, matching their representation in the JSON file.

Result:

Convert Json to Excel

3. Convert Excel to JSON Using Python

Next, read the orders.xlsx file you just created. The script uses the first row as the JSON field names and builds a dictionary from each subsequent row. It converts quantity back to an integer and keeps the other fields as strings.

To test the round trip, open orders.xlsx in Excel and change the first order’s status from Shipped to Delivered. Save and close the workbook, then run the script below.

import json from spire.xls import Workbook input_path = "orders.xlsx" output_path = "orders_exported.json" workbook = Workbook() try: workbook.LoadFromFile(input_path) sheet = workbook.Worksheets[0] headers = [ sheet.Range[1, col].Text for col in range(1, sheet.LastColumn + 1) ] orders = [] for row in range(2, sheet.LastRow + 1): # Skip blank rows between orders if not sheet.Range[row, 1].Text: continue order = {} for col, field in enumerate(headers, start=1): cell = sheet.Range[row, col] if field == "quantity": order[field] = int(cell.NumberValue) else: order[field] = cell.Text orders.append(order) finally: workbook.Dispose() with open(output_path, "w", encoding="utf-8") as file: json.dump(orders, file, ensure_ascii=False, indent=2) file.write("\n") 

The script writes orders_exported.json in UTF-8. The ensure_ascii=False option keeps non-ASCII characters readable if you later use data containing accented letters or other Unicode characters. The indent=2 option formats the output with two-space indentation. Open the exported file and verify that order 000147 now has the status Delivered.

This example assumes that the first column contains a required order ID, the first row contains unique, non-empty field names, and the quantity column contains integers . When adapting the script to a different worksheet, read each column according to the type of data it contains. For example, read prices as numbers and store and read product codes and postal codes as text to preserve leading zeros.

4. How Do You Handle Nested JSON?

Some APIs include a nested customer object or an array of line items within each order. Before converting this data, decide what each row in Excel should represent. You can flatten fields from the customer object, such as the customer’s name and city, into separate columns in the orders worksheet. If an order can contain multiple line items, put orders and line items on separate worksheets and link them using order_id. To recreate the original nested structure when exporting to JSON, group the line items by order ID.

Conclusion

When converting JSON to Excel, map fields to columns and records to rows, and write each value as text or a number according to its type. When converting Excel back to JSON, use the header row as the field names and restore each value to the appropriate type. Running both conversions on the same data lets you verify that order IDs retain their leading zeros, quantities remain integers, and status changes made in Excel appear in the exported JSON.