Rebuild nested data with JSON unflatten
JSON unflatten is the reverse of flattening. It takes an object whose keys are paths, such as "order.customer.name", splits each key on the separator and writes the value into a nested structure. It is the quickest way to turn a flat export, a translation file or a key-value dump back into readable JSON.
Example
Input:
{
"order.id": 1001,
"order.items.0.sku": "MUG-01",
"order.items.1.sku": "CAP-02"
}
Output:
{
"order": {
"id": 1001,
"items": [
{ "sku": "MUG-01" },
{ "sku": "CAP-02" }
]
}
}
Bracket indexes work too: "user.tags[0]": "admin" and "user.tags[1]": "beta" produce "tags": ["admin", "beta"], so output from JSON flatten in either array style can be pasted straight back.
Options explained
- Key separator: the string that splits a key into segments. Set it to
__to expand{"db__host": "localhost", "db__port": 5432}into{"db": {"host": "localhost", "port": 5432}}. - Numeric keys: Become arrays (default) turns segments like
0and1into array positions. - Numeric keys: Stay object keys keeps them as strings. Use this when numbers are identifiers, not positions.
- Indent: 2 spaces, 4 spaces or tabs.
Edge cases
Numbers that are really IDs
With the default setting, {"http.ports.80": "web", "http.ports.443": "tls"} creates an array with 444 slots, 442 of them null. Switch Numeric keys to Stay object keys and you get the intended {"http": {"ports": {"80": "web", "443": "tls"}}}. The same applies to HTTP status codes, years and database IDs.
Conflicting keys
If the input has both "a": 1 and "a.b": 2, the scalar is replaced by an object when the deeper key is processed, because a cannot be a number and an object at once. Keys are applied in the order they appear.
Input must be a flat object
Arrays and bare values are rejected with a clear message. Values themselves can be anything, including nested objects, which are copied as they are.
Unflatten vs. other tools
Unflatten works on JSON input. If your dotted keys live in a Spring application.properties file, use Properties to JSON, which parses the file format and nests keys in one step. For environment variables joined with __, the .env to JSON converter has a nesting option.
Where flat JSON comes from
- Translation files. Tools for i18n often store keys like
"nav.home.title". Unflatten them when a library expects nested objects. - Spreadsheet exports. Column headers such as
address.cityturn into flat keys after CSV to JSON; unflatten each record to get nested objects back. - HTML forms. Fields named
shipping.streetoritems[0].qtyare serialized as flat pairs, and unflattening shows the intended structure. - Logs and analytics. Many logging pipelines flatten events so each path becomes a searchable field.
Privacy
Everything runs locally in your browser; the JSON you paste is not uploaded.