Flatten nested JSON into one level of dot-notation keys

Paste nested JSON and get a single-level object back, where each key is the full path to a value, such as user.address.city or user.roles.0, plus a two-column table of every key and value.

Live demo · real result from this tool
Array indexes

Flat JSON

{  "id": 1024,  "name": "Asha Rao",  "email": "asha@example.com",  "active": true,  "roles.0": "admin",  "roles.1": "editor",  "address.city": "Pune",  "address.postcode": "411001",  "lastLogin": null}

9 keys

KeyValue
id1024
name"Asha Rao"
email"asha@example.com"
activetrue
roles.0"admin"
roles.1"editor"
address.city"Pune"
address.postcode"411001"
lastLoginnull

Processed on your device — nothing is uploaded.

How to use the JSON flattener

  1. Paste nested JSON into JSON. The root can be an object or an array.
  2. Set the Separator placed between path parts. The default is ..
  3. Pick how Array indexes look: a.0 (the separator again) or a[0] (brackets).
  4. Choose an Indent, then copy or download the Flat JSON, or read the key and value table under it.

What it does and when to use it

Nested JSON is natural for programs but awkward for tools that only understand one level of keys. Flattening helps when you:

  • load records into a spreadsheet or CSV, where each column needs one name;
  • compare two configs line by line, since every value now sits on its own line with its full path;
  • write translation files for i18n libraries that use flat keys such as checkout.button.pay;
  • build MongoDB $set updates or feature-flag keys that use dot paths.

Flat keys also make a document easy to search: find address.city once instead of scrolling through braces. To turn the flat object into environment variables, use JSON to .env; to reverse the process, use the JSON unflattener. The JSON key extractor lists the same paths in JavaScript accessor form, without building a new object.

How it works

The tool walks the parsed document depth-first and records each leaf value under the path it took to reach it. Object keys are joined with your separator; array positions are added either as plain numbers with the separator or as [n] with no separator before them. Strings, numbers, booleans and null are leaves. Empty objects and arrays are also stored as leaves so they are not lost. Keys come out in document order. A plain value at the root, such as 42, gives an object with an empty key.

All of this runs in your browser on the parsed value; nothing is uploaded.

Worked examples

{"user":{"name":"Asha","tags":["a","b"],"meta":{}},"active":true}

Default settings (separator ., indexes a.0), minified:

{"user.name":"Asha","user.tags.0":"a","user.tags.1":"b","user.meta":{},"active":true}

Separator / with a[0] indexes:

{"user/name":"Asha","user/tags[0]":"a","user/tags[1]":"b","user/meta":{},"active":true}

A root array [{"id":1},{"id":2}] gives {"0.id":1,"1.id":2}: the first path part is the item number.

Limits and tips

  • Key clashes are flagged: a literal key containing the separator can collide with a nested path, only the last value survives, and a warning names the key.
  • Large arrays produce one key per item, so a list of 10,000 records with 8 fields becomes 80,000 keys. For record lists, JSON to table is usually the better view.

Frequently asked questions

What happens to empty objects and arrays?
They are kept as values, so an empty "meta" object becomes the key user.meta with the value {} instead of disappearing. That way the JSON unflattener can rebuild them exactly.
Can I get it back to the nested form?
Yes. Paste the flat output into the JSON unflattener with the same separator. Numeric segments turn back into arrays, and bracket indexes are read too.
Which separator should I use?
The dot is the most common and is what lodash get/set, many i18n libraries and MongoDB field paths expect. Use / for JSON Pointer-like paths, or _ or __ when the keys will become environment variables. The separator can be up to 3 characters.
What if a key already contains a dot?
The tool does not escape it, so a literal key "a.b" and a key "b" nested inside "a" both produce the key a.b, and the later value overwrites the earlier one in the result, with a warning naming the key. Choose a separator that does not occur in your key names, such as / or |.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close