Skip to content
LocalOnly

JSON Flattener

Stable

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

Everything is processed locally in your browser

About JSON Flattener

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.

Features

  • Collapses arbitrarily deep objects into dot-notation key paths
  • Encodes array indices in the path, for example items.0.sku
  • Choose your delimiter, such as a dot, slash, or underscore
  • Preserves every leaf value with its original type
  • Ideal input for CSV export, config maps, and flat key-value stores
  • Round-trips with the JSON Unflattener to rebuild the original

How to use JSON Flattener

  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.

Reference

How each shape flattens

Nested inputFlattened keyNote
{"a":{"b":1}}a.bNested objects join with a dot
{"a":[1,2]}a[0], a[1]Array indices use brackets, not dots
{"a":[{"b":1}]}a[0].bBrackets and dots combine as the path requires
{"a":{}}(dropped)Empty containers hold no leaf values
{"a":null}anull is a leaf value and is preserved
{"a.b":1}a.bCollides with nested a→b; this is the one lossy case

Which tool should you use?

These tasks overlap. Here is how to pick the right one for what you are actually doing.

You are preparing nested JSON for a spreadsheet
The JSON to CSV tool flattens internally and writes the CSV in one step, so you do not need to do it separately.
You need to feed a flat key-value store or translation file
Flattening is exactly right, and the dotted-path output matches what most of those systems expect.
You want to find where a value lives in a large document
Flatten and search the keys. If you already know the shape, the JSON Path tool queries it directly without transforming anything.
You are restoring flat data back to nested form
The JSON Unflatten tool performs the inverse operation and understands the same bracket notation.

Use cases

  • Preparing nested JSON for import into a spreadsheet as columns
  • Turning a config object into flat environment-variable-style keys
  • Making structural differences obvious by comparing flat key lists
  • Loading JSON into a key-value store that expects flat keys
  • Building translation files where each string has a dotted path

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

What this tool deliberately does not do, so you know when to reach for something else.

  • 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