JSON Flatten
Collapse deeply nested JSON into one flat object of dot-notation paths, ready for diffing, grepping or a spreadsheet.
Nested JSON
Flattened JSON
Comparing two Helm values files, two Terraform outputs or two versions of an application config is painful precisely because the difference is buried six levels deep, and the structural noise around it makes a normal diff unreadable. Flattening rewrites the whole document as a single-level object whose keys are full paths — app.image.tag, app.env[1].value, ingress.hosts[0] — so every leaf value sits on its own line, next to a key that tells you exactly where it lives.
That shape is useful well beyond diffing. It is grep-friendly, it maps directly onto the dotted keys that Spring, Consul, Vault and most feature-flag systems use, it pastes cleanly into a two-column spreadsheet, and it makes "which of these two thousand settings actually changed" a question a line-based diff can answer.
How to use the json flatten
- 1
Paste the nested JSON
Any valid JSON document. Depth is not limited; deeply nested configs are the point of the tool.
- 2
Flatten
Every leaf value is emitted with its full path as the key. The result count tells you how many leaves the document actually contains, which is often a surprise.
- 3
Diff, search or export
Flatten both versions of a file, then run them through the Compare tool for a diff that shows only the paths that changed. Or copy the output straight into a spreadsheet.
The path notation
Paths follow the convention almost every configuration system already uses, so the output usually needs no translation:
- Object keys are joined with a dot.
{"app":{"image":{"tag":"2024.11.3"}}}becomes"app.image.tag": "2024.11.3". - Array elements use bracketed indices.
hosts[0],hosts[1], and for arrays of objects,env[1].value. - Empty containers are kept as leaves. An empty object stays
"annotations": {}and an empty array stays"tolerations": [], rather than vanishing — the difference between "empty" and "absent" is usually meaningful in a config file. - Scalar values keep their JSON types. Numbers stay numbers, booleans stay booleans,
nullstaysnull. Nothing is stringified.
The result is itself a valid JSON object, so you can format it, minify it, or feed it into any other tool on this site.
What flattening is good for
Config diffing. The headline use. Two nested files that differ in one field produce a wall of context in a structural diff; flattened, they produce one changed line. This is how you review a Kubernetes manifest change or a values file bump without missing the one setting that matters.
Making JSON greppable. Once every value is on a line with its full path, grep timeout answers "where are the timeouts configured" in one shot, across the whole document.
Bridging to key-value stores. Consul, etcd, AWS Parameter Store, Spring properties and most feature-flag platforms are flat dotted-key systems. Flattened JSON is a near-direct import format.
Spreadsheets and quick analysis. A flat object drops into two columns cleanly, which is often the fastest way to hand a config to someone who does not read JSON.
Limits worth knowing
Flattening is not perfectly reversible by convention alone. A key that already contains a dot — {"a.b": 1} — flattens to the same path as {"a":{"b":1}}, so an unflattener cannot tell them apart. If your keys contain dots or brackets, which is common in Kubernetes annotations and in DNS-style names, treat the flat form as a view for reading rather than a format to round-trip through.
Large arrays flatten to one entry per element, so a document with a ten-thousand-item array produces ten thousand keys. That is correct and occasionally overwhelming; flatten the sub-object you care about instead of the whole payload.
Array indices are positional, which has a practical consequence for diffing: inserting one element at the top of a list shifts every path below it, and a flattened diff will show the entire array as changed even though only one item was added. When you are comparing lists whose order is not meaningful, sort both sides before flattening, or compare the arrays separately.
Finally, flattening discards no data but does discard shape. The nesting is recoverable from the paths by eye, but the document no longer looks like the thing your application reads. Use it for inspection and comparison, not as the file you deploy.
JSON Flatten FAQ
How are arrays of objects handled?
Each element gets an indexed path segment, and nesting continues inside it: env[0].name, env[0].value, env[1].name. Because the index is positional, reordering an array changes every path in it — worth remembering when diffing two files whose lists are sorted differently.
Can I unflatten the result back to nested JSON?
Not with this tool. It is a one-way view. Reconstruction is ambiguous whenever an original key contained a dot or a bracket, so an automatic unflattener would silently reshape some documents.
What happens to empty objects and arrays?
They are preserved as leaf values — {} and [] respectively — rather than being dropped. Losing them would erase the distinction between a key set to an empty list and a key that is not there at all.
Does the output stay valid JSON?
Yes. The flattened result is a plain JSON object with string keys and the original scalar values, so every other tool here accepts it directly.
Is there a depth limit?
No fixed one. Documents nest as deeply as your data does and the resulting path keys simply get longer. Very deep structures produce unwieldy key names, which is itself a useful signal about the shape of the config you are looking at.
Does the flattened key order match the original?
Yes — leaves are emitted in document order, depth first, so a path and everything beneath it stay together. That is what makes the output diff cleanly against a second flattened file, provided both documents list their keys in the same order.
