π Available as a Fiverr service β Need a custom JSON or XML dataset turned into a clean, presentation-ready Excel report? Order the gig here
A professional Python toolkit that converts structured JSON (and XML) data into polished, fully-styled Excel workbooks β complete with dark-blue branded headers, alternating row colours, frozen header rows, auto-filters, auto-sized columns, image embedding, and an optional Summary dashboard sheet.
- What It Does
- Sample Schemas Included
- Features
- Project Structure
- Requirements
- Quick Start
- How It Works
- Output
- Adapting to a New JSON Schema
- Fiverr Gig
Raw API responses, database exports, and data dumps are rarely ready to share. This toolkit bridges that gap: you hand it a JSON or XML file, and it hands you back a professional .xlsx report that looks like it came out of a BI tool β without involving Excel at all.
The architecture is intentionally split into two layers:
| File | Role |
|---|---|
parser.py |
Generic engine β format-agnostic utilities for XML conversion, data inspection, Excel writing, and visual styling that work with any JSON structure |
main.py |
Domain script β wires the engine to a specific JSON schema, adds custom column formatting, image embedding, and summary statistics |
You extend the toolkit simply by writing a new domain script for your schema β parser.py never needs to change.
Three real-world schemas ship with the repository so you can see the converter in action right away:
| File | Description |
|---|---|
data/ecommerce_orders.json |
Nested e-commerce order payload with items, pricing, and payment status |
data/hotel_bookings.json |
Hotel reservation data with guest details, room types, and extras |
data/user_data.json |
Large user dataset from randomuser.me β 1000+ records with profile photos |
Pre-generated output files (orders_report.xlsx, hotel_report.xlsx, user_data.xlsx) are included for instant preview.
- β Nested JSON flattening β deeply nested structures mapped to clean tabular rows
- β
XML β JSON conversion via
xmltodictbefore processing - β Image embedding β downloads image URLs and inserts them directly into cells, sizing rows automatically
- β Duplicate-row deduplication built into the flattening step
- β Generic Excel styling β dark-blue headers, alternating row fills, frozen header row, auto-filter drop-downs, auto-sized column widths
- β Domain-specific colour-coding of status columns (Paid / Pending / Refunded / Failed)
- β Currency and percentage number formats applied per column
- β Auto-generated Summary sheet with KPI cards and ranked breakdown tables
- β Clean separation of concerns β swap in a new domain script without touching the engine
convert-json-to-excel/
β
βββ parser.py # Generic parsing & styling engine (reusable)
βββ main.py # Domain script β entry point (e-commerce + user schema)
βββ test.py # Quick workbook inspection helper
β
βββ data/
β βββ ecommerce_orders.json # Sample e-commerce payload
β βββ hotel_bookings.json # Sample hotel reservations payload
β βββ user_data.json # 1 000+ user records with photo URLs
β βββ orders_report.xlsx # Pre-generated output (ecommerce)
β βββ hotel_report.xlsx # Pre-generated output (hotel)
β βββ user_data.xlsx # Pre-generated output (users with embedded images)
β
βββ requirements.txt
βββ README.md
- Python 3.10+
- openpyxl
3.1.5β Excel workbook creation and styling - pandas
3.0.2β Data inspection helpers - xmltodict
1.0.4β XML β dict conversion - numpy, python-dateutil, tzdata (installed as transitive dependencies)
# 1. Clone the repository
git clone https://github.com/sadmanhsakib/json-parser.git
cd json-parser
# 2. Create and activate a virtual environment
python -m venv .venv
# Windows
.venv\Scripts\activate
# macOS / Linux
source .venv/bin/activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Run the converter against the bundled user dataset
python main.py
# β Produces data/user_data.xlsxOpen data/user_data.xlsx (or any of the pre-generated files) to see the fully styled output.
parser.py provides format-agnostic utilities. None of its functions know which JSON schema is being processed β they operate purely on the data structures passed to them.
Reads an XML file, parses it into a Python dict using xmltodict, then writes the result as a sibling .json file. Expects the XML to have a <root> top-level element.
A debugging helper. Prints the type, length, inferred column names, dtypes, and first few rows of any JSON-serialisable object via pandas.json_normalize. Useful when exploring an unfamiliar schema.
Accepts the flat list[dict] produced by a flattening function and writes it into a new openpyxl workbook, deriving headers automatically from dict keys.
Scans the specified column for HTTP image URLs, downloads each image into memory, embeds it into the corresponding cell, auto-sizes the row height, and clears the raw URL text so only the image is visible.
Applies the standard visual treatment to the active sheet:
| Feature | Detail |
|---|---|
| Header row | Dark-blue background (#1F3864), white bold text, centred, 30 pt row height |
| Data rows | Alternating white / light-grey fills |
| Navigation | Header row frozen at A2 so it stays visible while scrolling |
| Filtering | Auto-filter drop-downs across the entire header row |
| Column widths | Auto-sized to the longest cell value + 4-character padding |
Low-level helper that styles a single cell as a header. Reused internally and exposed for domain scripts that build custom sub-tables (e.g. the Summary sheet).
Six named hex constants are exported for use in any domain script:
DARK_BLUE = "1F3864"
WHITE = "FFFFFF"
LIGHT_BLUE = "D6E4F0"
LIGHT_GREY = "F5F5F5"
LIGHT_GREEN = "E2EFDA"
LIGHT_RED = "FCE4D6"
LIGHT_YELLOW = "FFF2CC"main.py is the executable entry point. It calls into parser.py for all generic work and adds domain-specific logic on top.
Orchestrates the full pipeline:
Load JSON β flatten rows β write workbook β embed images
β apply generic style β save .xlsx
Maps the user_data.json payload to flat rows. Handles:
- Composing a full name from
title,first, andlastname fields - Extracting nested location data (street, city, state, country, postcode, coordinates, timezone)
- Reformatting ISO-8601 timestamps to
YYYY-MM-DD HH:MM:SS - Preserving the thumbnail URL in a
Picturecolumn (later processed byimg_parser) - Deduplication of identical rows before writing
(Available for e-commerce schema)
Post-processes the workbook to add:
-
Status colour-coding on the
Payment Statuscolumn:Status Fill Paid Light green Pending Light yellow Refunded Light blue Failed Light red -
Number formats β
$#,##0.00applied to currency columns.
(Available for e-commerce schema)
Creates a separate Summary sheet (grid lines hidden) containing:
- KPI cards (rows 1β5): Total Orders, Total Revenue, Items Sold, Average Order Value β dark-blue label cells, large-font value cells
- Order Status breakdown (cols BβC, from row 9): ranked by count descending, alternating row colours
- Items Sold breakdown (cols EβF, from row 9): ranked by quantity descending, same visual treatment
- Auto-sized columns applied to the Summary sheet
Running python main.py against the bundled user dataset produces data/user_data.xlsx:
- Styled header row with auto-filter
- Profile photo thumbnails embedded directly in the Picture column
- Alternating row fills, frozen header, auto-sized columns
- All contact, location, login, and date-of-birth fields in clearly labelled columns
For the e-commerce schema (data/ecommerce_orders.json), the output includes a second Summary sheet with KPI cards and ranked breakdown tables.
- Create a new domain script (e.g.
invoices.py). - Import
parserand use its utilities directly. - Write your own flattening function that maps your JSON fields to the desired column headers.
- Call the standard pipeline:
import json, parser
def main():
with open("data/invoices.json") as f:
data = json.load(f)
rows = flatten_invoices(data) # your custom flattener
wb = parser.write_to_excel(rows, "Invoices")
wb = parser.apply_generic_style(wb) # free generic styling
# add your own custom_style() here if needed
wb.save("data/invoices_report.xlsx")
def flatten_invoices(data):
rows = []
for invoice in data["invoices"]:
row = {
"Invoice ID": invoice["id"],
"Client": invoice["client"]["name"],
# ... map remaining fields
}
if row not in rows:
rows.append(row)
return rows
if __name__ == "__main__":
main()parser.py never needs to be modified β all schema-specific logic lives in the domain script.
This toolkit was built as the backbone of a Fiverr data-conversion service. If you have a JSON or XML export that you need turned into a clean, branded Excel report β with custom columns, colour-coded status fields, embedded images, or a summary dashboard β you can order the service directly on Fiverr.
π Gig link: https://www.fiverr.com/s/38XgWrx8
What a typical order looks like:
| You provide | You receive |
|---|---|
| A JSON / XML file (any structure) | A fully styled .xlsx workbook |
| Column mapping preferences | Auto-sized columns, frozen header, auto-filters |
| Branding colours (optional) | Header colour-scheme to match your brand |
| Status field labelling (optional) | Colour-coded status cells |
| Dashboard requirements (optional) | A Summary sheet with KPI cards and breakdown tables |
Turnaround is typically 24β48 hours depending on order complexity.
Built with Python Β· openpyxl Β· pandas Β· xmltodict