OnlineTextLab
Esc

JSON Flattener

Collapses nested JSON into one level of paths such as user.address.city, with a warning if two values land on the same key.

Flat JSON output

Your Flat JSON appears here as you type.

Nothing to paste yet? Use Try an example to see it work.

Options
Path separator
List positions

Runs on your device. Your files and text are not uploaded.

About JSON Flattener

Plenty of tools only understand one level of keys: spreadsheets, environment variable loaders, translation platforms, key-value stores and some log search systems. Flattening rewrites a nested document so that the path to each value becomes its key.

It also helps people. A flat view makes a big document searchable with Ctrl+F, and comparing two flattened files in a diff tool shows exactly which paths changed, without noise from indentation.

You get a single-level JSON object, and the JSON Unflattener reverses it when both use the same separator.

How it works

The document is walked, and each plain value is written under its joined path. List positions become part of the path, as tags.0 or tags[0] depending on your choice. Your input's key order is kept.

Empty objects and empty lists are kept as values, since dropping them would make the conversion lossy: "preferences": {} stays there, and unflattening brings it back. Many simple flatteners lose these silently.

If two paths end up identical, for example a literal "a.b" key next to a nested a with b inside, the later value wins and a notice names the key. Choosing another separator usually fixes it.

How to use JSON Flattener

  1. Paste nested JSON, or use Open file to load it.
  2. Choose a Path separator. Slash and underscore suit tools where dots already mean something.
  3. Pick how List positions are written, such as tags.0 or tags[0].
  4. Collect the flat result with Copy or Download .json.

Nested objects, a list and an empty object

Input
{"user":{"name":"Ada","roles":["admin","editor"],"zip":null},"orders":[{"id":1}],"preferences":{}}
Output
{
  "user.name": "Ada",
  "user.roles.0": "admin",
  "user.roles.1": "editor",
  "user.zip": null,
  "orders.0.id": 1,
  "preferences": {}
}

Each list position got its own key. user.zip stayed as null, and the empty preferences object is kept rather than vanishing.

When it helps

  • Sending a nested translation file to a platform that wants flat keys such as home.title.
  • Comparing two API responses or config versions line by line in a diff tool.
  • Loading a document into a key-value store, or making it searchable in a log system.
  • Generating environment variables from nested config, with an underscore separator.

Tips for a better result

  • Sort the flat result before comparing two files. The JSON Formatter can sort keys, and sorted keys make a diff far more useful.
  • Use a double underscore if your keys contain single underscores. .NET configuration uses that separator for environment variables.
  • If your goal is a spreadsheet, JSON to CSV flattens objects as well and also lines the records up into rows.

Good to know

  • A lone value at the top level, such as 5, is refused, because there is nothing to flatten.
  • Keys that already contain your separator cannot be told apart from nesting when unflattened later.
  • A top-level list gives keys such as 0.name, and a large list gives a very long object.
  • The path syntax is this tool's own, not JSONPath or JSON Pointer, though the two are easy to convert between.

Questions people ask

Can it reverse the flattening?

Yes, the JSON Unflattener rebuilds the original if you use the same separator and none of your keys contain that separator. Empty objects and lists come back too.

How are lists flattened?

Each item's position joins the path, starting at zero, so roles: ["a", "b"] gives roles.0 and roles.1. Choose the bracket style to get roles[0] instead.

What happens when one of my keys already contains a dot?

It is written as it stands, so "a.b": 1 looks the same as a nested path. Pick a separator that does not appear in your keys if you intend to unflatten later.

Does this change my values?

No. Only the keys change. Strings, numbers, booleans and nulls are copied across, though very long integers are kept as text so no digits are lost, and a notice tells you if that applied.

What to use next

Last reviewed . Read our editorial policy.