JSON Flatten / Unflatten
Convert nested JSON to dot-notation key paths and back again.
- Recent results are kept in this browser's local storage until you clear them.
History kept on this device
Recent results are kept in this browser's local storage until you clear them. - Processing happens in this page. No application server receives your input.
Runs in your browser
Processing happens in this page. No application server receives your input.
Input
Output
What this tool does and what it does not do
This tool converts between a nested JSON document and a flat JSON object of path keys, in either direction. Output is always a single compact JSON document, not .env KEY=value lines, YAML, or Java properties, and no key-escaping scheme is invented. Every document that Flatten accepts under Brackets round-trips back to the same document under Unflatten. The reverse is not promised when an unflattened leaf value itself holds a nested object whose keys Flatten refuses (such as a key containing the separator).
Worked example and empty containers
Under the default Flatten direction, Brackets array notation, and . separator, {"a":{"b":[1,2]},"c":{}} flattens to {"a.b[0]":1,"a.b[1]":2,"c":{}}, and Unflatten turns {"a.b[0]":1,"a.b[1]":2,"c":{}} back into {"a":{"b":[1,2]},"c":{}}. An empty top-level object {} flattens and unflattens to {} with 0 keys, while a nested empty object {"a":{}} or empty array {"a":[]} is kept as a leaf value so the container is not lost on the round trip.
Named refusals and how to resolve them
- A key that contains the separator (for example
{"a.b":1}when the separator is.) or runs into a multi-character separator (for examplea_beside__) is refused by name rather than round-tripped wrongly. ChangeSeparatorto a sequence that does not appear in your keys (such as__or::). - Under
Brackets, a key containing[or]is refused because bracket notation reads brackets as array indices. ChooseDots (arrays become objects)when object keys literally contain brackets. - An empty key
""at any depth is refused because it has no path; rename the key first. Flattenrequires a top-level object or non-empty array;Unflattenrequires a top-level object of key paths, refuses malformed paths (such as.a,a.,a..b, or non-canonical brackets likea[01]), and refuses two keys that write to the same place.
Prototype-chain safety
The segment names __proto__, constructor, and prototype are refused in both Flatten and Unflatten at any depth (in a key, path segment, bracket under bracket notation, or nested value), even though they are valid JSON property names, so pasted data can never modify the JavaScript prototype chain. Case variants such as __PROTO__ and ordinary method names such as hasOwnProperty, toString, and valueOf are treated as normal data.
Bracket notation vs. dot notation and sparse or mixed levels
Brackets is the default because it writes array positions as [0], [1], โฆ and reconstructs dense 0..n-1 bracket levels back into arrays. Dots (arrays become objects) writes array indices after the separator (for example a.0), emits a warning when flattening a non-empty array, and unflattens numeric segments to plain objects with string keys. Under Brackets, a sparse bracket level such as {"a[1]":1} or a mixed level such as {"a[0]":1,"a.b":2} stays a plain object rather than allocating empty array holes.
Duplicate keys, IEEE-754 numbers, and key ordering
- When an input object repeats a key,
JSON.parsekeeps only the last value, and a warning names the path, line, and column (up to 1,000 warnings). - A number that IEEE-754 double precision cannot hold exactly (such as
9007199254740993) is rounded, and a number that overflows double precision becomesnull, with a warning. -0normalizes to0and1.0normalizes to1without a warning because their numeric values are equal.- JavaScript objects order canonical non-negative integer-like keys (
0,1, โฆ) before other string keys in insertion order.
Limits
Up to 16.0 MB of input, 64 levels of nesting, 200000 keys, 500000 nested containers, 16 separator characters, and 16.0 MB of output. A key containing the separator is refused rather than round-tripped wrongly, and dot notation turns arrays into objects. Input of 64.0 KB or more runs in the background, can be cancelled, and stops after 30 seconds. Input and output are saved in this browser when they fit.
| Bound | Limit | Behavior at the bound |
|---|---|---|
| Input size | 16.0 MB | Refused before parsing when UTF-8 input exceeds 16.0 MB. |
| Nesting depth | 64 levels | Refused before parsing when JSON nesting exceeds 64 levels, and during Unflatten when path segments plus leaf value nesting exceed 64 levels. |
| Input member names and output keys | 200,000 keys | Refused before parsing above 200,000 input member names, and during Flatten before storing key 200,001. |
| Nested objects and arrays | 500,000 containers | Refused in either direction before entering or creating container 500,001 below the root. |
| Separator length | 16 characters | Must be 1 to 16 UTF-16 code units with no bracket or ASCII digit. |
| Output size | 16.0 MB | Because repeated path prefixes can make flattened output much larger than the input, the running UTF-8 output byte count is checked before each path is built and refused past 16.0 MB. |
| Output box display slice | 256.0 KB (262,144 chars) | The Output box shows the first 256.0 KB on a whole character boundary while Copy copies the full output. |
| Background worker threshold and time budget | 64.0 KB / 30 s | Inputs of 64.0 KB or more run in a background worker where Cancel can stop the run and the 30-second time budget applies. Runs below 64.0 KB execute synchronously on the main thread and cannot be interrupted. |
Browser storage and credentials
Your input, output, and settings up to 131,072 characters are saved in localStorage in this browser under devstash_session_data-flatten and devstash_history_data-flatten. When a finished conversion's output pushes the saved state past 131,072 characters, the input and settings are kept while the output is not stored across reloads. Because saved state remains in this browser, any secret or credential pasted here stays in localStorage until you empty Input and press Clear history.
Scope: this covers the page itself. Your browser, operating system, clipboard, downloads, extensions, and crash recovery may keep copies, and a compromised site origin would not be protected.