JSON Flatten and Unflatten
Flatten deeply nested JSON into a single level of dot-notation keys, where nested objects join with a dot and array items use their index, so a.b and list.0 describe the whole path. Switch to unflatten to rebuild the original objects and arrays from those flat keys. The output is pretty-printed with a two-space indent, and you can set any delimiter you like in place of the dot.
How to flatten JSON
- Click Flatten to collapse nested JSON, or Unflatten to rebuild it.
- Optionally change the Delimiter field from the default dot to another character.
- Paste your JSON into the input box labelled Nested JSON or Flat JSON.
- Read the pretty-printed result; an error appears if the JSON cannot be parsed.
- Click Copy to take the result with you.
Examples
Flatten a nested object and array
{ "a": { "b": 1 }, "list": [10, 20] }{
"a.b": 1,
"list.0": 10,
"list.1": 20
}Unflatten dot keys back into structure
{ "a.b": 1, "list.0": 10, "list.1": 20 }{
"a": {
"b": 1
},
"list": [
10,
20
]
}Flatten with a slash delimiter
{ "user": { "name": "Ada", "roles": ["dev"] } }{
"user/name": "Ada",
"user/roles/0": "dev"
}Frequently asked questions
How are arrays represented when flattening?
Array items use their numeric index as a path segment, so the first item of list becomes list.0 and the second becomes list.1. When you unflatten, any segment made only of digits is turned back into an array position.
Can I change the delimiter?
Yes. The Delimiter field defaults to a dot but accepts up to three characters, such as a slash or an underscore. Use the same delimiter for unflatten that you used for flatten, or the paths will not split correctly.
Does flatten then unflatten return the original JSON?
For ordinary JSON, yes. The two operations are inverses, so flattening and then unflattening reproduces the same objects, arrays and leaf values.
What counts as a leaf value?
Strings, numbers, booleans and null are leaves and become the values of the flat keys. Only objects and arrays are descended into, so a null is preserved as null rather than expanded.
What happens to empty objects or arrays?
An empty object or empty array holds no leaf values, so it produces no keys at all when flattened. There is nothing to represent, so it simply disappears from the flat result.
What if a real key contains the delimiter?
A dot inside an actual key is indistinguishable from a path separator, so a key like a.b will be read as two segments on unflatten. If your keys contain dots, choose a delimiter that does not appear in them.
Why does unflatten sometimes create an array with gaps?
Container type is inferred from the digits in a segment, so keys like list.0 and list.2 build an array whose index 1 is empty. Provide every index if you need a dense array with no holes.
Does the tool require an object at the top level?
Flatten accepts any JSON, including a bare array or a single value. Unflatten expects a flat object of key to value pairs, and it warns you if you give it something else.
Is my JSON uploaded anywhere?
No. Everything is parsed and transformed in your browser, so your JSON stays on your device and nothing is sent to a server.
Learn more
- JSON dot notation for flattening and rebuilding data
How dot-notation keys encode a path through nested JSON, why array indexes appear as numbers, and how to unflatten safely.
Related tools
JSON Formatter
Format, validate and minify JSON online. Pretty-print with custom indentation, sort keys and catch syntax errors. Runs in your browser.
JSON to CSV
Convert JSON to CSV online. Paste an array of objects and get clean, spreadsheet-ready CSV with the right headers. Runs in your browser.
.env to JSON
Convert a .env file to JSON, or JSON back to .env. Parses KEY=value lines, comments, quotes and export. Runs entirely in your browser.
ASCII Table
Full ASCII table for all 128 codes with decimal, hex, octal and binary values, character names and descriptions. Search by code, hex or character.
Aspect Ratio Box Generator
Generate CSS for a responsive aspect-ratio container. Use the modern aspect-ratio property or the padding-top fallback, then copy the ready code.
Aspect Ratio Calculator
Calculate aspect ratios fast. Enter a ratio like 16:9 and one dimension to get the other, or enter width and height to simplify the ratio.