datapry

JSON Flatten / Unflatten

Turn nested JSON into flat dot-separated keys, or rebuild the nesting from them. Runs in your browser, so nothing is uploaded.

Mode
Indent

JSON input

Result

Waiting for input

About this tool

Flat keys are easier to use in spreadsheets, environment variables, translation files and search indexes. Flatten turns nested JSON into one level of keys such as user.address.city. Unflatten rebuilds the nesting, including arrays from numeric keys, and reports conflicting keys instead of silently overwriting them.

How to use it

  1. Choose Flatten or Unflatten.
  2. Set the separator, and whether array items use index keys.
  3. Paste JSON, then copy or download the result.

Example

Input
{"user":{"name":"Riya","address":{"city":"Kolkata"},"tags":["admin"]}}
Output
{
  "user.name": "Riya",
  "user.address.city": "Kolkata",
  "user.tags.0": "admin"
}

Questions

Can I always get the original back?
Yes, unless a key already contains the separator, such as a key named "a.b". You'll get a warning when that happens, so you can pick a different separator.
What happens to arrays?
With "Arrays as indexes" on, items become keys like tags.0 and tags.1, and unflattening turns them back into arrays. Turn it off to keep arrays whole as values.
What if two keys conflict when unflattening?
Keys like "a": 1 and "a.b": 2 can't both exist, because a can't be a number and an object at once. The tool stops and names the conflicting key.