JSON Flatten and Unflatten Online

Flatten nested JSON into one level of keys like user.address.city, or unflatten dot-notation keys back into nested objects. Choose the separator and how arrays are written. Runs in your browser, so your data is never uploaded.

JSON Input

Ln 1, Col 1Empty

JSON Result

Your result will appear here.
No result yet

What Does Flattening JSON Mean?

Flattening turns nested JSON into a single level: every value gets one key that spells out its path, such as user.address.city. Flat data fits places that have no nesting: CSV and spreadsheet columns, database fields, environment variables, translation files and analytics events. Unflattening does the reverse and rebuilds the nested structure from those keys.

How to Flatten or Unflatten JSON

  1. Paste your JSON, drop a .json file on the box, or load it from a link with URL.
  2. Pick the separator and how arrays should be written.
  3. Click Flatten to get one level of keys, or Unflatten to rebuild nested JSON.
  4. Copy or download the result, or send it to another tool with Open in.

Example

Nested JSON
{
  "user": {
    "name": "Emily",
    "address": { "city": "London" }
  },
  "roles": ["admin", "editor"]
}
Flattened
{
  "user.name": "Emily",
  "user.address.city": "London",
  "roles.0": "admin",
  "roles.1": "editor"
}

Options

OptionChoicesTypical use
Separator. _ __ / :Dots for most tools, __ for environment variables (DB__HOST), / for path-like keys, : for .NET configuration
Arraysroles.0, roles[0], or kept as listsBrackets match JavaScript and lodash paths; keeping lists flattens objects only
Numbers make arraysOn or off (unflatten)On: items.0 becomes a list. Off: "0" stays an object key

Things to Know

  • Empty objects and lists are kept as {} and [], so flattening and unflattening give back exactly the same JSON.
  • Keys that already contain the separator, like "file.name" with dot as separator, cannot be split back exactly. The tool counts them and suggests another separator.
  • Conflicting keys such as "a": 1 and "a.b": 2 cannot both exist in nested JSON; unflattening names the keys that clash.
  • Gaps in lists, for example only items.2, are filled with null so the result is valid JSON.

Tips

Frequently Asked Questions

How do I flatten nested JSON?

Paste the JSON and click Flatten. Every value gets one key that spells out its path, such as user.address.city, so the result has a single level. You can pick the separator and how arrays are written.

How do I unflatten dot-notation keys?

Paste a flat object such as {"user.name": "Emily"} and click Unflatten. The keys are split at the separator and rebuilt into nested objects; numeric parts like items.0 become arrays unless you turn that off.

Does flattening lose any data?

No. Empty objects and lists are kept, so flattening and unflattening return the same JSON. Only keys that already contain the separator cannot be split back exactly, and the tool tells you when that happens.

Is my JSON uploaded?

No. Flattening and unflattening run in your browser and your data never leaves your device.

Related Tools