Skip to content
LocalOnly

JSON Flattener

Stable

Flatten nested JSON into single-level dot-notation key paths.

Everything is processed locally in your browser

The JSON Flattener collapses deeply nested objects and arrays into a single flat object whose keys are dot-notation paths like user.address.city. Flattened JSON is far easier to feed into spreadsheets, environment variables, and key-value stores, and it makes comparing structures trivial. Array indices are preserved in the path so nothing is lost.

How to use it

  1. 1

    Paste nested JSON

    Add the object or array with the nested structure you want to flatten.

  2. 2

    Choose a delimiter

    Keep the default dot or pick a custom separator for the generated key paths.

  3. 3

    Flatten

    The tool produces a single-level object mapping each path to its leaf value.

  4. 4

    Export the result

    Copy the flat map for spreadsheets, env files, or comparisons.

Examples

Nested object to dot-notation keys

Input

{
  "user": {
    "name": "Mira",
    "roles": ["admin", "editor"]
  }
}

Output

{
  "user.name": "Mira",
  "user.roles.0": "admin",
  "user.roles.1": "editor"
}

How flattening JSON works

Flattening turns structure into path strings

Flattening walks a nested document depth-first and, for every leaf value it reaches, records the route it took to get there as a single string key. `{"user":{"address":{"city":"Oslo"}}}` becomes `{"user.address.city":"Oslo"}`. The values are untouched; only the keys change, absorbing the nesting that used to be expressed by braces.

Array elements get bracketed numeric indices, so `{"tags":["a","b"]}` becomes `{"tags[0]":"a","tags[1]":"b"}`. Keeping brackets rather than using another dot is what makes the operation reversible: `items[0]` is unambiguously an array index, while `items.0` could equally be an object key that happens to be the string `"0"`.

The result is always exactly one level deep, which is the whole point. A flat map of string keys to scalar values is the shape that spreadsheets, environment variables, translation catalogues, form libraries and key-value stores all expect.

What flattening is actually for

The most common reason is getting nested data into a tabular format. CSV has no way to express nesting, so a nested object must become columns named `user.address.city` before it can be a spreadsheet at all. Flattening is the step that makes that conversion possible.

The second is diffing and searching. A flat map is trivial to compare: two documents differ exactly where their key sets or values differ, with no tree-walking required. It is also grep-friendly, which is why flattened output is easy to scan for a value when you do not yet know where it lives.

The third is systems that only accept flat key-value pairs. Translation files, feature-flag stores, environment configuration, analytics event properties and many form-state libraries all want dotted paths rather than nested objects.

When flattening is lossless, and when it is not

For most documents the operation round-trips perfectly - flatten then unflatten and you get the original back. The bracket convention preserves the object-versus-array distinction, and leaf values keep their types.

Three cases break that guarantee. First, a key that already contains a dot: `{"user.name":"Ada"}` flattens to the same string as `{"user":{"name":"Ada"}}`, so unflattening cannot tell which one you started with. Second, empty objects and empty arrays have no leaf values, so a naive walk drops them entirely. Third, sparse or non-sequential array indices can be reconstructed as objects rather than arrays if the numbering has gaps.

None of these are common, but all of them are silent when they happen. If you are flattening as part of a pipeline rather than for a one-off look, it is worth round-tripping a sample and comparing it against the original before you trust the process.

Troubleshooting common errors

Empty objects and arrays disappeared

Why: Flattening records leaf values, and an empty container has none, so there is no key to emit.

Fix: If empty containers are meaningful in your data, note them separately before flattening. They cannot be reconstructed from a flat map alone.

Unflattening did not reproduce the original document

Why: Almost always a key that already contained a dot, which becomes indistinguishable from a nesting separator.

Fix: Check your source keys for dots before flattening. Renaming them upstream is the only reliable fix.

The output has thousands of keys

Why: A large array was flattened, producing one key per element per field - `items[0].name`, `items[1].name`, and so on.

Fix: Extract the array first with the JSON Path tool and convert it to CSV, where rows handle the repetition far better than keys do.

An array came back as an object after unflattening

Why: The indices were non-sequential or started above zero, so the reconstruction could not confirm it was an array.

Fix: Ensure indices run from 0 with no gaps, or accept the object form and convert it in code.

Limitations

  • Keys that already contain a dot collide with the path separator and cannot be round-tripped reliably.
  • Empty objects and empty arrays are dropped, since flattening records leaf values only.
  • Large arrays produce one key per element, which grows quickly.
  • Sparse or non-zero-based array indices may reconstruct as objects rather than arrays.
  • The separator is a dot and is not configurable, which keeps the output compatible with common consumers.

Frequently asked questions

Learn more

Command Palette

Search for a tool or command