Unflatten dot-notation JSON back into nested objects and arrays

Paste a flat JSON object whose keys are paths, such as checkout.button.pay or roles.0, and get the nested structure back, with numeric parts rebuilt as arrays.

Live demo · real result from this tool

Nested JSON

{  "user": {    "name": "Asha",    "address": {      "city": "Pune"    },    "roles": [      "admin",      "editor"    ]  }}

Processed on your device — nothing is uploaded.

How to use the JSON unflattener

  1. Paste a flat object into Flat JSON. Each key is a path, each value is what goes at the end of it.
  2. Set the Separator used in your keys: . by default, or something like / or __.
  3. Keep Numeric segments become array indexes ticked to rebuild arrays, or untick it to keep number-like parts as object keys.
  4. Choose an Indent and copy or download the Nested JSON.

What it does and when to use it

Flat key/value data is everywhere: translation files exported from a localisation platform, spreadsheet columns named address.city, form fields named items[0].qty, environment variables with double underscores, or the output of a flattening step you ran earlier. Most programs want the nested shape. This tool builds it without a script.

It is the exact reverse of the JSON flattener when you use the same separator and index style. After rebuilding, tidy the result with the JSON key sorter or check it against a schema with the JSON Schema validator.

How it works

Each key is split on the separator. Inside each part, bracketed numbers such as [0] are pulled out as array positions. With the numeric option on, a part that is only digits is also an array position. The tool then walks from the root, creating an object or an array for each missing step, depending on whether the next part is a name or a number, and puts the value at the end. If the very first part of the first key is a number, the root itself becomes an array, so {"0.id":1,"1.id":2} turns into [{"id":1},{"id":2}].

Keys are processed in the order they appear. Values are copied unchanged, so nested values already inside the flat object stay as they are. All of this happens in your browser.

Worked examples

Translation keys with one bracket index:

{"checkout.title":"Pay now","checkout.button.pay":"Pay",
 "checkout.button.cancel":"Cancel","errors[0]":"Card declined"}
{"checkout":{"title":"Pay now","button":{"pay":"Pay","cancel":"Cancel"}},"errors":["Card declined"]}

Environment-style keys with Separator __: {"db__host":"localhost","db__port":5432} gives {"db":{"host":"localhost","port":5432}}.

A postcode kept as a key, with the numeric option unticked: {"zip.0":"x"} gives {"zip":{"0":"x"}}. With it ticked, the same input would give an array.

Limits and tips

  • The input must be an object. An array returns a message asking for a flat object.
  • A separator that also appears inside real key names splits them too. Pick one that does not occur in your names.
  • A large index such as list.100000 creates an array with that many null items before it.

Frequently asked questions

Why did a number in my key turn into an array?
With "Numeric segments become array indexes" ticked (the default), a path part made only of digits is read as an array position, so roles.0 and roles.1 become a two-item array. Untick it when the numbers are real names, such as postcodes, HTTP status codes or years, and they stay object keys.
Why are there nulls in my array?
Arrays cannot have gaps in JSON. If the flat keys skip positions, such as list.2 without list.0 and list.1, the missing items are filled with null.
What if both "a" and "a.b" are keys?
They cannot both survive, because "a" would need to be a value and an object at once. Keys are applied in order, so the later one wins. With "a" first and "a.b" second, the result is an object with a.b set and the plain value of a lost, and a warning names the clashing key.
Does it understand bracket indexes?
Yes. errors[0] and a.c[0] are read as array positions with any separator, which is the format the JSON flattener writes when you pick a[0] indexes.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close