Flat JSON vs Nested JSON — When to Use Each (And How to Convert)
- Flat JSON uses single-level dot-notation keys; nested JSON uses true object hierarchy.
- Flat is better for CSV export, diff comparison, and forms; nested is better for APIs and type systems.
- Convert between them in one click with our flattener and unflattener.
Table of Contents
Nested JSON is the default when you design an API — it mirrors how real-world data is actually shaped. Flat JSON, with dot-notation keys like user.address.city, is a tactical structure used when you need to move data through systems that do not handle nesting well: spreadsheets, diff tools, flat config stores, some form libraries.
The choice between them is not about which is "better." It is about what the next system in your pipeline expects. This post walks through the trade-offs and shows how to convert both directions when you need to.
The Same Data in Both Shapes
Take a typical API response for a single user:
Nested:
{
"id": 42,
"user": {
"name": "Alice",
"email": "[email protected]",
"address": { "city": "NY", "zip": "10001" }
},
"subscription": { "plan": "pro", "renewsOn": "2026-12-01" }
}
Flat (dot-notation):
{
"id": 42,
"user.name": "Alice",
"user.email": "[email protected]",
"user.address.city": "NY",
"user.address.zip": "10001",
"subscription.plan": "pro",
"subscription.renewsOn": "2026-12-01"
}
Same information, different shape. The flat version has one level; the nested version has three. Which one you want depends entirely on what you are doing next.
When to Use Nested JSON
API payloads. Nested JSON mirrors domain models. A user has an address, a subscription, a set of preferences — real relationships map cleanly to nested objects. REST and GraphQL clients expect this shape.
Type systems. Generating TypeScript interfaces, Go structs, or Python dataclasses is trivial from nested JSON and awkward from flat dot-notation. Pair with our JSON to TypeScript generator for instant type definitions.
Human reading. Pretty-printed nested JSON is easier to scan — related fields cluster together visually. Flat JSON with long dot-notation keys feels noisier.
Validation. JSON Schema validators, Zod, Joi, and most runtime validators are designed for nested shapes. Trying to validate flat dot-notation keys requires custom logic.
Partial updates. It is easier to send or patch a subtree in nested JSON (PATCH /users/42 with a partial address object) than to reconstruct what subset of flat keys map to which subtree.
Sell Custom Apparel — We Handle Printing & Free ShippingWhen to Use Flat JSON
CSV and spreadsheet export. Flat JSON maps to a single row. Each dot-notation key becomes a column header. Nested JSON requires a flattening step first, or it ends up with columns full of serialized sub-objects.
Diff-friendly storage. When two payloads differ only in a deeply nested field, flat JSON produces a clean one-line diff. Nested JSON diffs include extra lines of indentation changes and sibling context — noise that makes reviews harder.
Key-value stores. Redis, DynamoDB single-attribute mode, and environment variables are fundamentally flat. If your data needs to live there, flatten it on the way in and unflatten on the way out.
Form submissions. HTML forms produce flat name/value pairs. If you name your fields user.address.city, the browser submits a flat payload your server can unflatten into the domain shape.
Simple indexing and search. If you want to search across all string values in a payload, flat JSON lets you iterate one level of keys instead of recursing a tree.
How to Convert Between Flat and Nested
Use the JSON Flattener — it does both directions with the same tool.
Nested to flat: Paste your nested JSON, click Flatten. The output is flat dot-notation. Full walkthrough in the flatten guide.
Flat to nested: Paste your flat JSON, click Unflatten. The output rebuilds the nesting. See the unflatten guide.
Both conversions happen in your browser. There is no upload, no server, no limit beyond browser memory. For round-trip scenarios (flatten, edit in Excel, unflatten back), the tool is designed to produce a stable output — flatten then unflatten gives you the original structure.
Flatten vs Normalize — Not the Same Thing
People sometimes use "flatten" and "normalize" interchangeably. They are different operations.
Flatten collapses nested structure into dot-notation keys. One input object produces one flat output object. The data is preserved; only the shape changes.
Normalize (in the database sense) splits a nested object into multiple flat tables linked by IDs. A user with an array of orders becomes a users table and an orders table, with a foreign key between them. That is a relational data modeling operation, not a simple restructuring.
Our JSON Flattener does flatten, not normalize. If you need to split nested arrays into separate tabular outputs, you need a tool like Pandas json_normalize() with record_path or a bespoke script. For the single-object flatten case, the browser tool is faster.
Convert Between Flat and Nested JSON
Flatten or unflatten in one click. Free, browser-based, no upload.
Open Free JSON FlattenerFrequently Asked Questions
Is flat JSON or nested JSON faster to parse?
Roughly the same. JSON parsing is O(n) in the size of the document regardless of nesting depth. The difference in real-world time is negligible — both parse in milliseconds for typical payloads under 1MB. Pick based on what the next consumer expects, not parsing speed.
Does flattening JSON lose any data?
No, not when you flatten and unflatten with the same delimiter. The round-trip is lossless: leaf values, types (strings, numbers, booleans, null, arrays) are preserved exactly. The only caveat is empty objects — an input of {"foo":{}} flattens to nothing because there are no leaves under it.
Which is better for APIs?
Nested. Every major REST and GraphQL convention uses nested payloads. Clients expect it, type generators produce cleaner output from it, and partial updates are easier to reason about. Flatten only when you hit a specific downstream system that requires flat structure.
Can I mix flat and nested in the same payload?
Yes, but it is usually a bad idea. Consumers expect a consistent shape. If you have some fields that are always dot-notation and others that are always nested objects, downstream parsers need to handle both, which adds complexity. Pick one shape per payload and be consistent.

