DEV Community

Cover image for Stop flattening your JSON just to export it to Excel
Alexandre Manuel
Alexandre Manuel

Posted on

Stop flattening your JSON just to export it to Excel

If you've ever needed to share structured Python data (like nested dicts or lists) with non-developers, chances are you've hit this classic wall:

Can you export that to Excel?

And suddenly, you're fighting two worlds that just weren't made for each other.

Most tools expect flat tabular data. Your data isn't flat. So you end up writing brittle custom converters, or flattening everything and losing structure. And don't even get me started on round-tripping that back into Python…

I got tired of it. So I built excel-serializer: a Python library that lets you treat Excel like JSON — you can dump() and load() complex, nested structures without losing anything.

What it does

  • Serialize any Python data structure (dicts, lists, nested combos) to .xlsx
  • Read it back with full fidelity — like json.load()
  • Structure is preserved across sheets, and stays human-readable/editable
  • Bonus: it also comes with a CLI for easy use in scripts or from the terminal

Install it

pip install excel-serializer
Enter fullscreen mode Exit fullscreen mode

Basic usage (Python)

import excel_serializer as es

data = {
    "users": [
        {"name": "Alice", "scores": [1, 2, 3]},
        {"name": "Bob", "scores": [4, 5, 6]},
    ],
    "meta": {"source": "generated", "count": 2},
}

# Write to Excel
es.dump(data, "data.xlsx")

# Read it back
loaded = es.load("data.xlsx")
Enter fullscreen mode Exit fullscreen mode

CLI usage

Let’s say you have a JSON file like this:

{
  "people": [
    {"name": "Alice", "age": 30},
    {"name": "Bob", "age": 25}
  ],
  "meta": {"created": "2025-03-26"}
}

Enter fullscreen mode Exit fullscreen mode

You can convert it to Excel with:

cat people.json | json2xlsx -o people.xlsx
Enter fullscreen mode Exit fullscreen mode

And convert it back:

xlsx2json -i people.xlsx > output.json
Enter fullscreen mode Exit fullscreen mode

That’s it — no flattening, no config, no lost nesting.

Why not use pandas / openpyxl / whatever?

Because most of those tools:

  • Expect tabular data (not trees of dicts and lists)
  • Flatten nested structures or choke on them
  • Don’t offer a load()/dump() API with guaranteed round-tripping
  • Require too much boilerplate for simple tasks

excel-serializer is opinionated but practical: it chooses a clear way to represent nested data across sheets and makes it dead simple to work with.

Try it out

📦 PyPI
💻 GitHub Repo

Whether you’re building internal tools, working with analysts, or just want a better way to share structured data, give it a shot — and let me know what breaks 😄

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay