Convert nested JSON to flat dot-notation paths and back
Deeply nested JSON is hard to search, compare, and feed into flat data stores. This tool flattens any JSON object into a single-depth map where each key is a dot-separated path to the original value — user.address.city instead of three levels of nesting. Array indices become numeric path segments like items.0.name. The unflatten direction reverses the process: give it a flat map of dot-notation keys and it reconstructs the full nested structure with arrays and objects in the right places. Round-trip fidelity is preserved — flatten then unflatten returns the original structure.
How to flatten or unflatten
- 1Paste a nested JSON object into the left editor.
- 2Select "Flatten" to convert to dot-notation, or "Unflatten" to reconstruct nesting from flat keys.
- 3Click Process. The transformed result appears on the right.
- 4Copy the output or chain it into another tool like Diff or Table.
Under the hood
- Dot-notation path generation — Each leaf value gets a fully qualified path built by concatenating parent keys with dots. Nested objects like
{ a: { b: { c: 1 } } }become{ "a.b.c": 1 }. - Array index preservation — Arrays are flattened with numeric indices as path segments:
users.0.name,users.1.name. This preserves element order and allows precise round-tripping. - Lossless round-trip — Flatten followed by unflatten reproduces the original structure exactly, including arrays, nested objects,
nullvalues, and booleans. - Unflatten path parsing — The unflatten algorithm splits each key on dots, detects numeric segments to create arrays vs objects, and merges paths into a single tree.
- Leaf-only output — Only primitive values (strings, numbers, booleans,
null) appear in the flattened result. Intermediate objects and arrays are represented solely by their paths.
Real-world scenarios
- Environment variable mapping — Flatten a
config.jsoninto dot-notation keys that map directly to environment variables or.propertiesfile entries. - Elasticsearch / flat-store ingestion — Some data stores require flat documents. Flatten before indexing, unflatten when displaying results.
- Side-by-side diff of nested structures — Flatten two deeply nested objects, then diff the flat versions to see exactly which leaf values changed without navigating nesting.
- CSV column headers — Use flattened keys as column headers when converting nested JSON to tabular formats —
user.address.citybecomes a column name. - Form data serialization — HTML forms with bracket notation (user[address][city]) map naturally to dot-notation flat structures.
Before and after
// Nested input:
{
"user": {
"name": "Alice",
"address": { "city": "New York", "zip": "10001" }
},
"tags": ["admin", "editor"]
}
// Flattened output:
{
"user.name": "Alice",
"user.address.city": "New York",
"user.address.zip": "10001",
"tags.0": "admin",
"tags.1": "editor"
}Questions
What happens to arrays during flattening?
Array elements are assigned numeric path segments. An array like ["a", "b"] at path tags becomes "tags.0": "a" and "tags.1": "b". During unflattening, numeric path segments trigger array creation instead of object creation.
Can I flatten arrays at the root level?
The tool expects a JSON object as input. If your root value is an array, wrap it in an object first: { "data": [...] }. The flattened output will use data.0, data.1, etc.
Are keys with dots in the original handled?
Currently, dots in original key names are not escaped, which means a key like "my.key" would be ambiguous after flattening. Avoid keys containing literal dots, or pre-process them with a different delimiter.
Is the round-trip truly lossless?
Yes, for standard JSON structures. Flatten then unflatten preserves all types, nesting, and array ordering. The only caveat is keys containing dots, as noted above.