JSON Flatten & Unflatten

Flatten nested JSON into dot/bracket key paths and rebuild it back, with a live two-way preview between the nested and flattened forms.

Key map

Each key is a path: a dot steps into an object and [n] into an array. A dot or a bracket that belongs to a real key name gets a backslash in front of it here, so it is not read as a step and comes back unchanged when the JSON is rebuilt.

Result: 5 lines, 40 characters

Flatten and unflatten JSON in your browser

Paste a nested JSON object and instantly see it collapsed into a single-level map of path keys and values. Object properties are joined with dots and array items use bracket indices, so {"a":{"b":1},"c":[2,3]} becomes {"a.b":1,"c[0]":2,"c[1]":3}. Setting Write array items to after the delimiter you chose switches c[0] to c.0, and a key that is itself a whole number then carries a backslash so it comes back as a key. The two panels stay in sync: edit either the nested JSON or the flattened JSON and the other side is recomputed live, then copy whichever result you need with one click. Under the flattened box, Key style switches the keys to ENV-style or Column-style, and Key prefix and Key suffix add text around each key; keys changed that way are written for another file and go one way only, so the flattened box turns read-only until Paths with no prefix or suffix are chosen again.

Lossless, predictable round-trips

Flattening and unflattening are exact inverses of each other. Numbers, booleans, strings and null are preserved as-is, and empty objects and arrays are kept as leaf values so nothing silently disappears. Numeric path segments rebuild arrays while named segments rebuild objects, meaning any structure you flatten can be reconstructed byte-for-byte. This makes the tool handy for diffing config files, building form field names, or preparing flat key/value data for spreadsheets and environment files.

Frequently asked questions

How are arrays represented in the flattened keys?

Array items use bracket indices appended to the key, like c[0] and c[1]. Nested arrays stack their indices, so a value at m[1][0] means the first element of the second inner array. With Write array items set to after the delimiter, they are written c.0 and c.1 instead. Unflattening turns a bracket index back into a real array, and in that mode a whole-number segment too.

Can I edit either side and convert both ways?

Yes, while the Key style is Paths with no Key prefix or Key suffix. The tool is then fully two-way: type or paste into the Nested JSON box to flatten it, or edit the Flattened JSON box to rebuild the nested structure. If a side is not valid JSON an inline message appears and the other side simply waits until the input parses. Two flattened keys that would write the same place, such as a and a.b, or tags[0] and tags.x, are refused by name instead of one value replacing the other.

Can I choose what joins the path segments?

Yes. The delimiter can be a dot, an underscore, a double underscore or a slash, and a key that contains the chosen delimiter is escaped so it still comes back unchanged.

Can I get keys for an .env file or a spreadsheet header, and see the type of each value?

Yes. Key style offers ENV-style (USER_NAME) and Column-style (user_name) beside the default Paths, with array indices turned into the same kind of segment, and Key prefix and Key suffix add fixed text to each key — APP_ for a set of environment variables, say. Paths that would collapse into the same key are refused, naming the key, rather than losing a value. These keys go one way, so the flattened box turns read-only while they are chosen. The folded Key map lists each key in the chosen style with the type of its value: string, number, boolean, null, empty object or empty array.

Can it tell me which paths differ between two JSON files?

Not on this page, but the site’s JSON Diff tool, linked from here, does: paste two documents and it lists every added, removed and changed value by its full path, such as user.roles[0], without flattening them first. This page is for turning one document into flat keys and back.