
Flatten / unflatten JSON
Flatten nested JSON into a single-level object with dotted (or custom-separator) keys, e.g. "address.city", or reverse a flat object back into nested JSON objects and arrays. Runs entirely on your device.
Flatten / unflatten JSON collapses nested data to one level, each key built from its path and joined by separator, default a period. Unflatten reverses that, expanding a flat object into objects and arrays. An empty object or array survives as its own leaf value. A level rebuilds as an array only when every key is purely numeric.
Questions
What does flatten produce?
A single-level object whose keys are dotted paths, for example address.city, built from separator, default a period.
How are array indices represented?
As numeric path segments, the same as any object key, for example tags.0 and tags.1.
What happens to an empty object or array?
It is kept as its own leaf value at that path rather than disappearing.
How does unflatten decide between an object and an array?
A level whose keys are all purely numeric is rebuilt as an array; any other level becomes an object.
What input does unflatten require?
A flat JSON object at the top level; an array or scalar there is refused.
Can I use a custom separator?
Yes, set separator to anything other than the default period, on both the flatten and the matching unflatten call.
Compare
| Tool | Runs on the CLI | Live as you type |
|---|---|---|
| Flatten / unflatten JSON | Yes | Yes |
| Query a SQLite database | Yes | No |
| Profile a CSV dataset | Yes | Yes |
| Diff two CSV datasets | Yes | No |
| JSONL processor | Yes | Yes |
| Filter / grep a log file | Yes | Yes |