How to Unflatten JSON — Restore Nested Objects from Dot-Notation Keys
- Unflatten rebuilds a nested object from flat dot-notation keys — the reverse of flattening.
- Works with any delimiter (. _ / etc.) — tell the tool which separator your flat keys use.
- Runs in your browser; common for converting form submissions or config files back to structured JSON.
Table of Contents
Unflattening is the reverse of flattening: you start with a flat object where keys look like "user.address.city" and end with a fully nested object. Paste your flat JSON into our JSON Flattener, pick the delimiter you used, and click Unflatten. The original nesting is rebuilt in one pass — no code, no install.
The most common reason to unflatten is that some system stored your data in a flat key-value format (form submissions, flat config files, database rows with dotted column names) and you need to feed it to an API or library that expects proper nested JSON. Unflattening restores the structure without you writing any parsing logic.
What Unflattening Actually Does
Unflatten splits each key on your delimiter and rebuilds the tree one segment at a time. A key like "user.address.city" with value "NY" becomes the path user → address → city → "NY". If multiple keys share a prefix, they are merged under the same parent object.
Flat input:
{
"user.name": "Alice",
"user.address.city": "NY",
"user.address.zip": "10001",
"active": true
}
Unflattened output:
{
"user": {
"name": "Alice",
"address": { "city": "NY", "zip": "10001" }
},
"active": true
}
Keys with no delimiter (like "active") stay at the root. Keys with multiple delimiters produce deeper nesting.
When You Actually Need to Unflatten
Form submissions with dot-notation field names. Some frameworks (older Rails, plain HTML with bracket syntax in POST data) emit flat payloads like {"user.email":"[email protected]"}. Unflattening converts these to the nested shape your API expects.
Round-tripping through a spreadsheet. You flattened nested JSON, opened it in Excel, edited values, saved back as JSON. Now you need the original structure. Unflatten rebuilds it.
Flat config files. Application properties files (Spring, dotenv-style) use dot-notation keys. To feed those values into a JSON-expecting tool, unflatten first. Pair with our JSON Formatter for validation.
Database export cleanup. A SQL view with columns named user_address_city, user_address_zip exports to JSON as flat keys. Unflatten with delimiter set to _ to produce clean nested output.
Step-by-Step: Unflatten Your JSON
1. Open the JSON Flattener.
2. Paste your flat JSON in the input panel. Keys should all be strings with delimiters separating path segments.
3. Set the delimiter to match what your flat keys use — . for user.name, _ for user_name, / for user/name.
4. Click the blue Unflatten button (not Flatten). The output panel shows the nested object immediately.
5. Copy the result. If you want it compact, run it through the JSON minifier; if you want it pretty-printed with sorted keys, use the JSON Sorter next.
Edge Cases That Trip People Up
Delimiter character inside a value. If your original data had dots in string values (URLs, filenames, email addresses), unflatten treats them as path separators only in keys — values are never split. So {"site.url":"example.com/path"} unflattens cleanly because the dot in "example.com" lives in the value, not the key.
Delimiter character inside a key name. This one is trickier. If a real key has a dot in its name (rare but legal: {"version.1.0": true}), unflattening will split it into path segments and produce {"version":{"1":{"0":true}}}. The fix is to use a different delimiter — pick a character that never appears in your real key names, like ~ or |.
Root-level arrays. The tool only unflattens into root objects. If your original data was an array, wrap it: unflatten produces an object first, then you can manually extract the array value.
Numeric keys. If your flat keys look like "items.0.name", unflatten produces {"items":{"0":{"name":"..."}}} — the "0" becomes an object key, not an array index. Our tool does not auto-detect numeric segments as array indexes. If you need that, a code library like lodash's set() with array-index detection is required.
Unflatten Your JSON in One Click
Paste, set your delimiter, click Unflatten. Nested structure rebuilt instantly.
Open Free JSON FlattenerFrequently Asked Questions
What is the difference between flatten and unflatten?
Flatten takes nested JSON and produces a flat object with dot-notation keys. Unflatten does the opposite — it takes a flat dot-notation object and rebuilds the nested structure. They are exact inverses: flattening and then unflattening the same JSON produces the original (as long as you use the same delimiter).
Can I unflatten JSON that uses underscores instead of dots?
Yes. Set the delimiter field to underscore (_) before clicking Unflatten. The tool supports any single or multi-character delimiter, so you can also use slash (/) or custom separators.
Why does unflatten produce objects with numeric keys instead of arrays?
This tool treats every segment as an object key, including numeric ones like "0" or "1". If your flat keys represent array indexes, the output will have object keys like {"items":{"0":"a","1":"b"}} instead of {"items":["a","b"]}. To get real arrays, either post-process the output or use a library that auto-detects numeric segments.
Does unflatten work if my JSON has no nesting?
Yes, it is a no-op in that case. Keys without a delimiter stay at the root. An input like {"a":1,"b":2} unflattens to {"a":1,"b":2} unchanged.

