JSON Flattener
Flatten nested JSON into path keys and unflatten it back
Paste nested JSON or load an example to flatten it.
How to use
- 1.Choose Flatten or Unflatten, then paste JSON, upload or drop one .json file, or load an example.
- 2.Pick the delimiter (. / _ or __) and whether array indexes use brackets (items[0]) or the delimiter (items.0).
- 3.In Flatten mode, choose JSON object, Key=value lines or Environment variables as the output.
- 4.Read the round-trip check and any listed issues; each issue names the exact paths involved.
- 5.Copy the result or download flattened.json, unflattened.json, flattened.txt or flattened.env. Use Unflatten this output to check the reverse direction.
What JSON Flattener does
JSON Flattener turns nested objects and arrays into one level of path keys such as user.address.city or users[0].name, and rebuilds nested JSON from those keys. Flat keys are handy for configuration systems, translation files, spreadsheet columns, search indexes and diffs that are hard to read when data is deeply nested. Strings, numbers, booleans, null, empty objects and empty arrays keep their types, and numbers beyond JavaScript precision such as 9007199254740993 are written with their exact digits.
Collisions, conflicts and the round-trip check
Flattening is only reversible when every key parses back to its original path. A key that already contains the delimiter (for example "a.b" with the dot delimiter) or two paths that produce the same flat key are reported with both paths; the first value is kept and nothing disappears without a warning. When unflattening, a key that needs a path to be both a value and an object (user and user.name), an index far past the end of an array, or gaps in an array are reported too, and gaps are filled with null. After every JSON run the tool performs the inverse operation and compares the result, so "Round trip verified" is a real check, not a promise.
Environment variables, limits and privacy
Environment variable names are upper-cased, camelCase words are split with _, accents are removed and any character outside A–Z and 0–9 becomes _, so database.primary.port becomes DATABASE_PRIMARY_PORT. Names starting with a digit get a _ prefix, and names that collide are reported. Key=value and environment output are one-way formats. Object keys that look like integers are listed first because that is how JavaScript orders them, nesting deeper than 256 levels is kept as one value, and inputs over 2 MB are processed when you select the main action. Everything runs in your browser and the JSON is never uploaded.
Frequently asked questions
- How are arrays written when JSON is flattened?
- By default each array item gets a bracket index attached to its parent key, so users[0].name and users[1].name. You can switch to delimiter indexes such as users.0.name; when unflattening in that style, every canonical whole-number segment (0, 12, not 01) becomes an array index.
- Can I always get the original JSON back after flattening?
- Only when no key collides. If a key already contains the delimiter, or two paths produce the same flat key, the tool lists both paths, keeps the first value and marks the output as not exactly reversible. After every JSON run it performs the inverse operation and compares the results, so a verified round trip is an actual check.
- How are environment variable names built?
- The flat path is upper-cased, camelCase words are split with an underscore, accents are removed and every character outside A-Z and 0-9 becomes an underscore, so database.primary.port becomes DATABASE_PRIMARY_PORT. Names that start with a digit get a leading underscore, and two paths that produce the same name are reported instead of overwriting each other.
