JSON Flatten / Unflatten
Convert nested JSON to dot-key form and back — perfect for env files and i18n bundles.
{
"app.name": "DevTools",
"app.version": "1.0.0",
"features.auth.enabled": true,
"features.auth.providers[0]": "google",
"features.auth.providers[1]": "github",
"features.billing.enabled": false,
"i18n.en.hello": "Hello",
"i18n.en.bye": "Bye",
"i18n.fr.hello": "Bonjour",
"i18n.fr.bye": "Au revoir"
}Tips
- Use
.for i18n / dotenv-style keys, or/for path-style. - Arrays serialize as
items[0].namewhen bracket mode is on, otherwiseitems.0.name. - Keys containing the delimiter are escaped as
["my.key"].
About JSON Flatten / Unflatten
JSON Flatten converts a nested JSON object into a flat map keyed by dot-paths — `user.address.city` instead of `{ user: { address: { city: ... } } }` — and the inverse: take a dot-keyed map and rebuild the nested structure. Array indices are encoded with brackets (`tags[0]`) or as plain numeric segments depending on the option you choose.
Reach for it when nesting is in your way. Common targets: `.env` files where every variable is `SECTION_NAME` rather than `section.name`, i18n bundles where each translation key is a flat path, OpenAPI parameter lists, and feature-flag configs that want one row per leaf. The flatten direction is also a useful debugging step — listing every leaf path makes it obvious what a payload contains. Round-tripping flatten then unflatten reproduces the original document on well-formed input, so the tool is safe to use as an intermediate step in a longer transformation.
Examples
{"user":{"name":"Ada","tags":["a","b"]}}{"user.name":"Ada","user.tags[0]":"a","user.tags[1]":"b"}Flatten with bracket array notation. The option toggle switches to plain numeric segments or to a custom separator.
Frequently asked questions
Does flatten then unflatten round-trip?
Yes on well-formed input. Flatten then Unflatten gives back the original document, including arrays and nested objects.
What if a key in the source contains a dot?
Choose a non-dot separator (the option lets you use `_`, `/`, or a custom string), or escape the dot. Otherwise the resulting flat key is ambiguous on the way back.
Is this useful for env files?
Yes. Flatten the JSON to dot-keys, then run a per-line transform to upper-case the path, replace dots with underscores, and add an `=` between key and value to produce a valid `.env` file.
How is this different from JSONPath?
JSONPath queries an existing tree (extract values by path); Flatten transforms the tree into a path map (every value becomes its own entry). They are complementary — flatten first to enumerate all paths, then JSONPath to extract subsets.
