Flatten JSON / Unflatten JSON

Flatten nested JSON objects into dot-path keys, or unflatten dot paths back into nested objects and arrays.

Flatten nested JSON into dot paths

Flatten JSON converts nested objects into one flat object whose keys describe each path, such as user.address.city. Flat keys are easier to search, map to spreadsheet columns, store as environment-style settings or compare line by line. Choose Unflatten JSON to rebuild the nested structure from those paths.

The conversion runs entirely in your browser and keeps strings, numbers, booleans, null and empty containers exactly as they were. The result is pretty-printed with two-space indentation, ready to copy.

How to use it

  1. Pick Flatten JSON or Unflatten JSON in the Operation menu.
  2. Paste valid JSON into Input JSON. For unflatten, paste a flat object whose keys are dot paths.
  3. Click Run. Invalid input shows the parser message under the output box.
  4. Click Copy to take the result, or switch the operation and paste the output back in to check the round trip.

Worked examples

1. Flatten a nested object

{"user":{"name":"Ada","address":{"city":"London","zip":"N1"}},"active":true,"note":null,"meta":{}}

Flatten JSON output:

{
  "user.name": "Ada",
  "user.address.city": "London",
  "user.address.zip": "N1",
  "active": true,
  "note": null,
  "meta": {}
}

Every leaf value gets a full path. null is kept, and the empty meta object stays as {} so unflattening can restore it.

2. Unflatten JSON with array indexes

Numeric segments create arrays when the parent does not exist yet:

{"order.id":17,"order.items.0.sku":"A1","order.items.0.qty":2,"order.items.1.sku":"B2","order.items.1.qty":1}

Unflatten output:

{
  "order": {
    "id": 17,
    "items": [
      {
        "sku": "A1",
        "qty": 2
      },
      {
        "sku": "B2",
        "qty": 1
      }
    ]
  }
}

3. Keys that contain a slash

When unflattening, each segment is decoded the way JSON Pointer does it: ~1 becomes / and ~0 becomes ~. That lets you rebuild OpenAPI-style path keys:

{"paths.~1api~1v1.method":"GET","paths.~1api~1v1.auth":"token"}

becomes

{
  "paths": {
    "/api/v1": {
      "method": "GET",
      "auth": "token"
    }
  }
}

Edge cases and limits

Flatten JSON or use another tool?

Flattening is the right step when a target system wants one key per value: a mapping file, a translation catalogue, a feature-flag store or a key-value database. If you want spreadsheet rows, JSON to CSV and JSON to Table build columns from nested records directly. To read a single deep value without changing the document, query it with the JSONPath tester. To see exactly which paths changed between two versions of a config, the JSON diff checker reports differences by path.

Flatten JSON in code

For a repeatable pipeline, the same dot-path convention takes a few lines of Python. This version also walks lists, writing indexes as path segments, so its output unflattens correctly with the tool above:

def flatten(obj, prefix=""):
    out = {}
    items = obj.items() if isinstance(obj, dict) else enumerate(obj)
    for key, value in items:
        path = f"{prefix}.{key}" if prefix else str(key)
        if isinstance(value, (dict, list)) and value:
            out.update(flatten(value, path))
        else:
            out[path] = value
    return out

In pandas, pd.json_normalize(records, sep=".") flattens nested dictionaries into column names in the same style, though it leaves lists as cell values. Whichever route you use, unflatten a sample of the output and diff it against the source before trusting a large batch.

FAQ

What does it mean to flatten JSON?

Flattening turns a nested structure into a single-level object whose keys are paths. {"user":{"name":"Ada"}} becomes {"user.name":"Ada"}. Unflattening is the reverse.

Which separator does the tool use?

A dot. The separator is not configurable, and keys that already contain a dot are written unchanged, so they cannot be told apart from nesting when you unflatten later.

How do I get arrays back when I unflatten JSON?

Use numeric path segments. items.0.sku and items.1.sku rebuild an items array with two objects. Missing indexes become null.

Can I unflatten bracket paths like user[0].name?

No. Only dot-separated segments are recognised, so user[0].name becomes a key literally named user[0]. Rewrite brackets as user.0.name first.

Are value types preserved?

Yes. Strings, numbers, booleans and null pass through untouched, and empty objects and arrays are kept as values under their own path.

Is my JSON uploaded?

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