Why flatten JSON?
Databases and log systems often store nested JSON, but analysis tools (spreadsheets, BI, pandas json_normalize) want flat rows. Flattening converts {"user":{"address":{"city":"Shanghai"}}} into user.address.city = "Shanghai" — one line per leaf value.
What the tool does
- Dot notation: nested objects become
parent.child.keypaths. - Arrays: each element gets an index (
orders.0.id) — toggle it off to keep just the first element or aggregate keys. - Values: strings, numbers, booleans and nulls are preserved; nested objects and arrays are always expanded to leaves.
- CSV export: one header row + one data row — the classic shape for spreadsheet ingestion.
Use cases
- Pasting an API response to inspect every field path (great with the JSONL Tools).
- Preparing nested records for a CSV import in a tool that only accepts flat columns.
- Writing JMESPath-style queries by seeing the full path list first.
Everything runs locally — your JSON never leaves the tab.
Where it breaks down
flatten() walks the structure and joins keys with dots while array indices go into brackets, producing a single-level map where every leaf is reachable by one path. The purpose is downstream: a flattened object drops straight into a spreadsheet column set, a key-value store or a log line, whereas the nested original needs bespoke traversal code.
Formats, sizes and other limits
Flattening is lossy — there is no unflatten here, and the original hierarchy cannot be reconstructed without extra rules. Keys that already contain a dot or a bracket become ambiguous with the path syntax. Arrays are expanded by index, so sparse arrays produce gaps. Circular references recurse until the stack runs out. Numeric precision follows JavaScript's double representation.
Privacy: no data leaves this tab
The structure is walked in memory and printed back into the page. No key path is logged, transmitted or stored between visits.
Frequently asked questions
Can I reverse it?
Not with this tool. Round-tripping needs the original shape or an escaping convention; flattening alone discards both.
What if a key contains a dot?
It becomes indistinguishable from a path separator. Rename those keys first, or accept the ambiguity knowingly.
How are arrays handled?
Indices become bracketed path segments. A sparse array keeps its gaps, which is usually what you want for debugging.