Skip to content
Devtoolry

JSON Flatten / Unflatten

Flatten nested JSON into single-level path keys like user.tags[0], or unflatten them back. Choose the delimiter and array style; round-trips without losing data.

Runs in your browser · Nothing uploaded · No sign-up

Something not working, or missing a feature? Send feedback

About the JSON Flatten / Unflatten

JSON Flatten turns a nested document into one flat object whose keys are paths, like user.roles[0], which is easier to diff, search, store in a spreadsheet or send as form fields. JSON Unflatten rebuilds the original nesting from those keys, so the two directions round-trip without losing data.

Everything runs in your browser, so your input is never uploaded to a server.

How to use the JSON Flatten / Unflatten

  1. Choose Flatten, or Unflatten to rebuild nested JSON from path keys.
  2. Paste the JSON and pick the delimiter and the array style (a[0] or a.0).
  3. Copy the result. Swap moves the output back into the input and flips the direction.

Examples

Flatten a nested document

Input

{
  "id": 7,
  "user": { "name": "Ada", "roles": ["admin", "dev"] },
  "orders": [{ "sku": "A1", "qty": 2 }],
  "meta": {}
}

Result

{
  "id": 7,
  "user.name": "Ada",
  "user.roles[0]": "admin",
  "user.roles[1]": "dev",
  "orders[0].sku": "A1",
  "orders[0].qty": 2,
  "meta": {}
}

Objects are joined with dots and array items get an index in brackets. The empty meta object is kept as a value.

Rebuild the nesting

Input

{
  "user.name": "Ada",
  "user.roles[0]": "admin",
  "user.roles[1]": "dev",
  "active": true
}

Result

{
  "user": {
    "name": "Ada",
    "roles": [
      "admin",
      "dev"
    ]
  },
  "active": true
}

Keys such as user.roles[0] create the user object and the roles array again.

Common mistakes

  • Keys that contain the delimiter. A key like "a.b" flattens to the same path as {"a": {"b": ...}}, so unflattening cannot tell them apart. Choose a delimiter that does not occur in your keys.
  • Sparse array indexes. If you unflatten only a[0] and a[2], the missing slot is filled with null so the array keeps its positions.
  • Expecting arrays to stay arrays. After flattening, an array is just numbered keys. Unflatten needs the same array style (a[0] or a.0) that was used to flatten.

Works well with the JSON Flatten / Unflatten

Frequently asked questions

Can I use another separator than a dot?

Yes: slash, underscore or colon. Pick a character that does not appear in your keys, otherwise Unflatten cannot tell a key containing the delimiter from nesting.

What happens to empty objects and arrays?

With Keep {} and [] on, they stay as values, so unflattening restores them. Turn it off to drop them from the flat result.

Is the result the same as the usual flatten libraries?

For the common dot-and-bracket style, yes: arrays are shown as a[0], like the output of many flatten libraries. Choose a.0 for the style that treats array indexes as plain keys.

Why does unflatten reject a key like __proto__?

Building objects from untrusted keys can pollute the prototype of every object. The tool refuses those names, so pasting data from an untrusted source is safe.