How to Flatten JSON into Dot-Notation Keys

How to Flatten JSON into Dot-Notation Keys

To flatten JSON means turning a nested object into a single level of keys, where each key is a path like user.address.city. It is one of the quickest ways to move structured data into a flat format that other tools understand. Here is when you need it and how to do it in seconds.

Why flatten JSON at all

A nested object is great for reading, but a lot of systems only accept flat key-value pairs. Flattening solves that:

  • Environment variables: turn config into DATABASE.HOST style keys you can export.
  • Spreadsheets and CSVs: one column per leaf value, no nested cells.
  • Key-value stores: Redis, etcd, and similar stores want a flat namespace.
  • Config diffing: comparing two flat lists of paths is far easier than diffing nested trees.

Unflattening is the reverse: take those dotted keys and rebuild the original nested structure. The JSON Flatten / Unflatten tool does both directions.

Flatten JSON in three steps

  1. Open the JSON Flatten / Unflatten tool and paste your nested JSON.
  2. Choose your delimiter, then click flatten to get single-level dot-notation keys.
  3. Copy the result, or paste a flat object and click unflatten to rebuild the nested version.

Everything runs in your browser, so your data never leaves your device.

Choosing a delimiter

The default delimiter is a dot, which reads naturally as user.address.city. Switch it when a dot would clash with your keys or your target system. Underscores suit environment variables, and brackets or slashes can be clearer for deeply nested paths. The key is to pick a character that does not already appear in your own key names, so unflattening can split the path back correctly.

How arrays are handled

Arrays flatten by index, so tags[0], tags[1], and so on, or with numeric keys like tags.0 depending on your delimiter choice. That keeps order intact and makes every element addressable. When you unflatten, those numeric segments rebuild back into a proper array rather than an object, so a round trip returns the same shape you started with.

Paste your object, pick a delimiter, and flatten or unflatten in one click.

← All posts