How to Unflatten JSON: Rebuild Nested Data from Flat Keys
Learn how to unflatten JSON from dot notation, bracket notation, slash paths, or underscore keys, rebuild arrays, and convert flat JSON back to nested JSON.
Flat JSON is useful when data needs to fit into tables, logs, search indexes, or column-based exports. But APIs and apps usually want nested JSON again. To unflatten JSON means converting flat path keys like user.address.city back into real nested objects and arrays.
This guide explains how to use an online JSON unflatten tool, how dot notation and bracket notation work, how numeric keys become arrays, and when delimiter auto-detection is safe.
The quickest way: unflatten JSON online
Paste a flat object into the JSON Unflatten tool, keep delimiter detection on Auto, and press Unflatten JSON. The tool rebuilds nested JSON in your browser, so your data is not uploaded.
Use it for flattened API responses, spreadsheet exports, analytics payloads, log events, NoSQL exports, localization files, and config maps.
Use it when: you need to convert flat JSON to nested JSON without writing a script.
What unflattened JSON looks like
Flat JSON with dot notation:
{
"user.id": 7,
"user.address.city": "London",
"user.address.postcode": "W1"
}
Unflattened nested JSON:
{
"user": {
"id": 7,
"address": {
"city": "London",
"postcode": "W1"
}
}
}
Only the object structure changes. Strings, numbers, booleans, and null values stay as real JSON values.
Dot notation to nested JSON
Dot notation is the most common flat-key format:
{
"profile.name": "Ada",
"profile.company.name": "Example Co"
}
Each dot separates one path segment. When you unflatten JSON, profile.company.name becomes profile > company > name.
Dot notation is common in JavaScript utilities, data exports, search indexes, and many flatten JSON libraries.
Bracket notation JSON keys
Some tools create bracket notation keys instead:
{
"user[address][city]": "London",
"user[address][country]": "UK"
}
The JSON Unflatten tool can parse bracket notation and rebuild nested objects from those keys. It also supports slash paths like user/address/city and underscore keys like user_address_city.
Rebuild arrays from numeric keys
Flattened arrays usually use numeric path segments:
{
"roles.0": "admin",
"roles.1": "editor"
}
With numeric-key coercion enabled, this becomes:
{
"roles": ["admin", "editor"]
}
Turn this option off if numeric keys should remain object properties instead of array indexes.
Auto-detect delimiter or choose manually?
Auto-detect is convenient for normal flat JSON because it can recognize bracket notation, slash paths, dot notation, and underscore keys. Choose a delimiter manually when:
- Keys contain more than one delimiter style.
- Underscores are part of real field names.
- Dots appear in literal property names.
- You know the exact format used by the source system.
Manual delimiter selection prevents ambiguous keys from being interpreted the wrong way.
Unflatten JSON in JavaScript
A simple dot-notation unflatten function looks like this:
function unflatten(input) {
const output = {};
for (const [path, value] of Object.entries(input)) {
const parts = path.split(".");
let cursor = output;
parts.forEach((part, index) => {
if (index === parts.length - 1) {
cursor[part] = value;
} else {
cursor[part] ??= {};
cursor = cursor[part];
}
});
}
return output;
}
Production tools add delimiter choices, bracket parsing, array coercion, validation, sorting, and download support.
Which method should you use?
For one-off conversion, use the online JSON Unflatten tool. It is fastest when you need to rebuild nested JSON from flat keys, especially with dot notation or bracket notation. Use JavaScript when unflattening is part of your app, build process, or data pipeline.
Need the reverse operation? Use JSON Flatten to flatten nested JSON, then compare shapes with JSON Diff or inspect the rebuilt object in JSON Viewer.
Ready to merge your JSON?
Combine files or snippets in your browser — free and private.
Open the merge toolKeep reading