Skip to content
UniKit

JSON flatten

Flatten nested JSON into flat key-value pairs and unflatten it back: custom delimiters, an array expansion switch, both bracket and index array styles, plus conflict detection.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

Conversion settings

Keys containing the delimiter are rejected; on unflatten an object whose keys are consecutive 0..n-1 becomes an array.

Result

What this tool does

  • Collapse nested config or API responses into one level of key-value pairs for flat-only stores such as spreadsheets, environment variables or analytics fields.
  • Produce a.b.c style field names for systems that expect dotted paths (Elasticsearch, log pipelines); arrays expand to a[0], a[1].
  • The reverse direction is just as common: read flat keys from an events table or a dictionary and rebuild the nested JSON to paste back into code.
  • Sanity-check data shape first: the leaf count and maximum depth are shown right away, so you can tell whether the structure is one level deeper than expected.

Example

Input

{"user":{"name":"Ada","tags":["math","code"]},"active":true}

Output

{
  "user.name": "Ada",
  "user.tags[0]": "math",
  "user.tags[1]": "code",
  "active": true
}

Paste that flat object into "Unflatten" and you get the original nested structure back; the array keys are consecutive 0 and 1, so they are restored as an array.

Frequently asked questions

What if a key already contains the delimiter?

With the default dot delimiter, a key containing a dot would be indistinguishable from a path separator and could not be restored reliably, so it is rejected with an error. Switch to a delimiter that cannot appear in your keys (underscore, slash) or rename the key first.

Can I choose how array indexes are written?

Yes. Brackets are the default (a[0], a[1]) and suit dotted-path systems; the index style (a.0, a.1) is easier to use as a plain field name. Unflatten understands both forms.

What happens when arrays are not expanded?

With array expansion off, the whole array becomes a single JSON-string leaf, so [1,2] turns into "[1,2]". That is what you want when the array does not need to be searched and should just be carried around as-is.

How are empty containers and deep structures handled?

Empty objects and arrays have no children, so they become the leaves "{}" and "[]". The default maximum depth is 64; anything deeper is serialized to a JSON string instead of being expanded, which keeps malformed data from blowing up the conversion.

How does unflatten decide between an array and an object?

After rebuilding, an object whose keys are exactly the consecutive numbers 0..n-1 becomes an array; if any key is not a number, or the numbers have gaps (only 0 and 2, say), it stays an object. That rule makes flatten and unflatten round-trip, and it also means input like {"a.0":1} restores to the array [1].

Keywords:json flattenunflattenflat jsonkey pathnested jsondelimiterJSON 扁平化扁平键值对展开嵌套还原 JSON

Related tools