Tool Kumar tool
JSON flatten and unflatten
Paste nested JSON to get one flat object whose keys are paths, such as user.address.city or orders[0].sku. Paste flat JSON and choose Nested JSON (unflatten) to nest it again. Every value keeps its exact digits, and the JSON never leaves your device.
How to use this tool
- Paste nested JSON or open a file. The Convert view shows it flattened.
- Set the separator, the array indexes and the depth in the More options menu (⋯). To unflatten, choose Nested JSON (unflatten) in the converter menu instead.
- Copy or download the result. Use as input (Ctrl+Enter, or ⌘Enter on a Mac) puts it in the editor and switches to the other direction, so you can check that it converts back. Ctrl+Z undoes it.
Worked example
Each value gets one key: object keys are joined with dots and array items get [0], [1]. The empty tags array and meta object stay as values, and the 16-digit id keeps every digit.
Input
{
"id": 9007199254740993,
"user": {
"name": "Ada",
"email": null,
"roles": ["admin", "editor"],
"address": {
"city": "London",
"zip": "N1"
}
},
"orders": [
{ "sku": "A1", "price": 12.50, "gift": false },
{ "sku": "B2", "price": 7 }
],
"tags": [],
"meta": {}
}Output
{
"id": 9007199254740993,
"user.name": "Ada",
"user.email": null,
"user.roles[0]": "admin",
"user.roles[1]": "editor",
"user.address.city": "London",
"user.address.zip": "N1",
"orders[0].sku": "A1",
"orders[0].price": 12.50,
"orders[0].gift": false,
"orders[1].sku": "B2",
"orders[1].price": 7,
"tags": [],
"meta": {}
}How to unflatten JSON
Choose Nested JSON (unflatten) in the converter menu and paste the flat JSON. Each key is split at the separator, and a bracketed index such as [0] becomes an array item. Array items are placed in index order; if an index is missing, its place gets null and the notice says how many.
Flat JSON:
{"id":7,"user.name":"Ada","user.roles[0]":"admin","user.roles[1]":"editor","user.address.city":"London","tags":[]}
Unflattened:
{
"id": 7,
"user": {
"name": "Ada",
"roles": [
"admin",
"editor"
],
"address": {
"city": "London"
}
},
"tags": []
}Keys that contain dots or brackets
A key such as user.name would read as two levels when unflattened. With Escape keys on, flatten writes a backslash before the dot, and unflatten turns it back into one key. A bracket gets a backslash too, and a backslash in a key is doubled. In JSON text each backslash shows as two.
To keep keys exactly as they are, choose a separator your keys do not contain, such as a slash, or turn Escape keys off. The notice then counts the keys that would come back differently.
Input:
{"user.name":"Ada","user":{"id":7},"price[EUR]":12}
Flattened:
{
"user\\.name": "Ada",
"user.id": 7,
"price\\[EUR]": 12
}
Notice: Escaped 2 keys with a backslash so that Unflatten restores themWhen unflattening finds a conflict
Some flat objects ask for two different values in one place: "a": 1 and "a.b": 2 need a to be a number and an object at once. Instead of keeping one and dropping the other, Tool Kumar shows an error that names both keys and counts any further conflicts. The same happens when a key appears twice, or when a[0] and a.b would make a both an array and an object.
Flat JSON:
{"a":1,"a.b":2}
Unflatten error:
Keys "a" and "a.b" conflict: one holds a value, the other goes inside itOptions and edge cases
- Separator: a dot by default; a slash, an underscore, two underscores, or any text of up to 8 characters without digits, backslashes or brackets. Unflatten splits keys with the same setting.
- Array indexes: a[0] (default), a.0 with your separator, or None to keep arrays whole as values. With a[0], only bracketed indexes become array items when unflattening; with a.0, a path part made only of digits does, unless its object also has other keys.
- Depth: All flattens every level. 1, 2 or 3 joins only that many levels into keys and keeps deeper objects and arrays as values.
- Empty objects and arrays stay as {} and [], null, true, false, numbers and strings stay as they are, and keys keep their order.
- A top-level array is read as a list of records, as CSV rows are: each item is flattened on its own. Unflatten reads a list of flat records the same way. A single value has nothing to flatten and stays as it is.
- Escape keys, on by default, puts a backslash before characters a path would misread, such as a dot inside a key, so unflattening restores the key exactly. A notice above the output counts these keys, and warns about duplicate keys or anything else that would not convert back.
Private by default
Your document stays in this browser. Tool Kumar parses, converts and creates downloads on your device, with no account or upload step.
JSON flatten and unflatten questions
- How are arrays flattened and unflattened?
- By default each item gets its index in brackets: tags[0], tags[1], and orders[0].sku for a value inside an item. Choose a.0 in the menu to write the index as another path part, or None to keep arrays whole. Unflatten turns the same style back into arrays.
- Can I use a separator other than a dot?
- Yes. Pick a slash, an underscore or two underscores in the More options menu, or type your own of up to 8 characters. Digits, backslashes and brackets are not allowed because paths use them for indexes and escapes.
- What happens when two flat keys clash?
- Unflatten stops and names both keys, for example "a" and "a.b", or the same key given twice. No value is dropped silently. Fix or rename one of the keys and the nested JSON appears.
- Are empty objects, empty arrays and null kept?
- Yes. An empty object stays {} and an empty array stays [] under its own key, and null stays null, so unflattening gives back the same document.
- Do big numbers and key order survive?
- Yes. Values are copied from your text, so an ID such as 9007199254740993 or a long decimal keeps every digit instead of being rounded, and keys keep their order in both directions.
Related tools
JSON to CSV, JSON to table, JSON path finder, JSON formatter.