toolgarden.xyz
中文

JSON Flatten / Unflatten

Free online tool to flatten nested JSON / JSONC / JSON5 into path keys, or restore nested structures from path keys

Input JSON / JSONC / JSON5

Output

Converted result will appear here

About this tool

Flatten rewrites nested objects and arrays as one object mapping paths to leaf values, such as user.address.city becoming one key. Unflatten reads those paths and rebuilds containers, which is useful when moving data through spreadsheets, environment variables, or key-value stores that do not support nesting.

The delimiter is part of the format. If an original key already contains the same dot or custom delimiter, the flattened result is ambiguous. Array indexes also need to remain numeric path segments so unflatten can rebuild arrays instead of ordinary objects.

How to use it

  1. Choose flatten or unflatten

    Flatten accepts nested JSON; Unflatten accepts a one-level object whose keys encode paths.

  2. Confirm the path delimiter

    Use a separator accepted by the destination and absent from original property names.

  3. Review arrays and empty containers

    Check array indexes, empty objects, empty arrays, and keys containing punctuation after conversion.

Input and output example

Nested structure against its path-key form. Array positions are written as bracketed indexes.

Nested JSON
{
  "user": {
    "name": "kit",
    "tags": ["a", "b"]
  }
}
Flattened
{
  "user.name": "kit",
  "user.tags[0]": "a",
  "user.tags[1]": "b"
}

Supported range and limits

Two directions
Flatten nesting into path keys, or rebuild nesting from path keys
Path notation
Dots join object levels and brackets index arrays, as in user.tags[0]
Typical use
Getting nested JSON into somewhere that only accepts flat key-values: environment variables, spreadsheet columns, some config systems
Precondition for rebuilding
Path keys must be well-formed; hand-typed paths with mistakes will not reconstruct correctly
Keys containing dots
An original key with a dot in it becomes ambiguous once flattened, and unflattening gets it wrong
Empty objects and arrays
They have no leaf to flatten to, so these empty containers can be lost on the round trip

When you would use it

  • Creating spreadsheet columns

    Turn nested configuration into stable path columns for filtering, comparison, and bulk editing.

  • Preparing environment variable mappings

    Flatten a hierarchy, then adapt the delimiter to the naming convention used by the deployment system.

  • Flattening deep nesting for field-by-field review

    A deeply nested config becomes a list of paths you can compare line by line against another copy; more reliable than clicking through a tree.

What to know before you start

  • If a real key contains the delimiter there is no lossless way to distinguish key text from a hierarchy boundary.
  • Sparse arrays can contain empty positions after reconstruction; JSON serialization usually renders those positions as null.
  • Empty objects and arrays have no leaf value, so preservation depends on whether the flattening format records a placeholder.

Related concepts

leaf value
A final value with no child members; each flattened path normally points to one leaf.
delimiter
The character joining path segments, such as a dot or greater-than sign, which must not collide with real keys.

Frequently asked questions

What do flatten and unflatten each do?
Flatten turns nested JSON into a single level of path keys like a.b.c; unflatten rebuilds those path keys back into nested objects.
What do the flattened keys look like?
Nested objects are joined with dots and arrays use indexes, e.g. user.tags.0, which is handy for config entries, i18n keys or table columns.
Does processing upload my data?
No. Both flatten and unflatten run locally in your browser and data is never uploaded.
Why does unflattening not reproduce the original?
Two common causes: an original key containing a dot becomes ambiguous once flattened, and empty objects or arrays have no leaf to flatten to and so disappear. Both need a human check.
How are array indexes written in a path?
In brackets, as in `user.tags[0]`. Hand-written paths must use that form consistently, or unflattening treats the index as an ordinary key name rather than an array position.