How to use
- Choose Flatten or Unflatten at the top.
- Paste JSON or drop a
.json,.jsonlor.ndjsonfile. Files up to 20 MB are read. - Pick the path separator, array path style, array handling and depth. The result updates immediately.
- Copy or download the result. Use result as input runs the opposite direction so you can check that it returns the original.
What flattening means
Every value in nested JSON gets a single key made of its path, such as order.customer.name, so the result is a one-level object. This JSON
{"order":{"id":"A-1001","customer":{"name":"Kim","tier":"VIP"},"items":[{"name":"T-shirt","qty":2},{"name":"Cap","qty":1}],"tags":["new","gift"],"note":null}}
is flattened like this with the default settings.
{
"order.id": "A-1001",
"order.customer.name": "Kim",
"order.customer.tier": "VIP",
"order.items.0.name": "T-shirt",
"order.items.0.qty": 2,
"order.items.1.name": "Cap",
"order.items.1.qty": 1,
"order.tags.0": "new",
"order.tags.1": "gift",
"order.note": null
}
Options
The same input with other settings.
| Setting | Result |
|---|---|
| Array paths: Brackets | "order.items[0].name": "T-shirt" |
| Arrays: Keep value arrays, spread object arrays | "order.tags": ["new","gift"] (the items array of objects is still spread) |
| Output: path = value list | One line per value like order.customer.name = "Kim". Strings are quoted so they differ from numbers |
| Spread depth: 2 levels | "order.customer": {"name":"Kim","tier":"VIP"}. Anything below level 2 is left as is (top-level keys are level 1) |
| Flatten each item separately | When the input is an array, flatten every item and return an array of flat objects, the same shape as table rows |
| Path separator | Dot, slash, underscore, double underscore or colon. With a slash the keys read order/customer/name |
Unflatten rules
- Keys like
a.0,a.1that run from 0 without gaps become an array. If 0 is missing, as ina.1,a.2, it stays an object. Turn off “Turn keys 0, 1, 2… into arrays” to always get objects. - Bracket style
a[2]always means an array; empty slots are filled withnull. Indexes above 100,000 are skipped to protect memory. - If one key is both a value and the start of another key (
a: 1anda.b: 2) that is a conflict. The later key is skipped and you are told which one. - If the input is an array of flat objects, each item is rebuilt.
- Keys such as
__proto__are treated as ordinary keys and do not touch built-in object behavior. - Under JavaScript object rules, integer-like keys such as
"1"and"2"always come first in ascending order.
Keys that contain the separator
{"a.b": 1, "a": {"b": 2}} would give a.b for both and overwrite one. This tool puts a \ before separators and backslashes inside a key to tell them apart.
{"a\\.b": 1, "a.b": 2}
In JSON the backslash is written twice as \\, but the first key is really a\.b. Unflatten reads that \ back, so the original shape returns. If you turn off “Escape separators inside keys”, the result is {"a.b": 2} and a notice says an earlier value was overwritten.
Good to know
- Numbers such as
12345678901234567890,10.50and1e3change value if read as JavaScript numbers; this tool keeps their original text. - Beyond 500,000 values only the beginning is flattened and you are told. Nesting is read up to 200 levels.
- A syntax error is reported with line, column and cause. Trailing commas, single quotes and unquoted keys are the usual ones.
FAQ
What is JSON flattening used for?
Whenever you need values addressed by a path rather than by structure: environment variable and properties formats that use keys like db.host, translation file keys, spreadsheet columns, or searching a single field in logs.
What is the difference between .0 and [0]?
Both point to the first item of an array. With dot style (a.0.b) the key alone cannot say whether a is an object or an array, so unflattening guesses an array only when the numbers run from 0. Bracket style (a[0].b) states it is an array from the start, so it is more precise.
I want to see the flattened result as a table.
JSON to Table flattens each row into columns, shows the table, and exports CSV or Markdown.
Some keys disappeared after unflattening.
Conflicting keys are skipped, and the skipped keys are listed above the result. Check whether a value and an object share the same path.
Related tools: JSON Formatter, JSON to CSV Converter, JSON ↔ YAML Converter, JSON Diff
Your JSON and files are processed in this browser and never sent to a server.