JSON Flattener

Flatten nested JSON into single-level dot-path keys — in your browser.

Free online JSON flattener. Collapse nested objects and arrays into a single-level object with dot-path or bracket keys. Privacy-first: your JSON never leaves your browser. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

How are arrays flattened?

By default array items use the delimiter and a numeric index (roles.0, roles.1). Enable bracket notation to get roles[0], roles[1] instead, which round-trips cleanly with most unflatten tools.

JSON flattener

Deeply nested JSON is awkward to diff, map onto environment variables or store in a flat key/value system. This tool collapses a nested JSON object or array into a single-level object where every leaf value is keyed by its full path, so the whole structure becomes a tidy list of path/value pairs.

How it works

The flattener walks the JSON recursively, building up a path as it descends:

  • Object keys are appended using your chosen delimiter (a dot by default), so a then b becomes a.b.
  • Array items append their index — roles.0 in dot mode, or roles[0] if you enable bracket notation.
  • Empty objects and arrays are kept as leaf values ({} / []) at their path so nothing is lost and the structure can be rebuilt exactly.

Each leaf value (string, number, boolean or null) is copied unchanged.

Example

This nested input:

{ "user": { "name": "Sam" }, "roles": ["admin", "editor"] }

flattens (with dot indices) to:

{
  "user.name": "Sam",
  "roles.0": "admin",
  "roles.1": "editor"
}

Switch on bracket notation and the array keys become roles[0] and roles[1], which round-trips cleanly through the unflatten tool. Everything runs in your browser — your JSON never leaves your device.

Why flatten JSON at all?

Nested JSON is excellent for representing hierarchical data, but it creates friction in several common workflows:

Version control diffs. A diff of two deeply nested JSON config files is hard to read because the structural indentation adds noise. Flattening both versions first produces a list of key: value pairs that diff cleanly — it is immediately obvious which leaf value changed.

Environment variables. Many deployment platforms accept configuration as flat key/value pairs. A flattened JSON object maps directly onto environment variables: DATABASE_HOST, DATABASE_PORT, REDIS_URL and so on. After flattening, you can export each key as a shell variable or paste them into a .env file.

Key/value stores and spreadsheets. Systems like Redis, DynamoDB (in simple mode), or a spreadsheet with path/value columns expect flat data. Flattening converts a nested document into rows a key/value store can ingest directly.

Quick inspection of a leaf value. Sometimes you just want to find where a specific value lives in a deeply nested API response without counting indentation levels. Flattening shows every value with its full path so you can scan or search instantly.

Delimiter choice matters for round-tripping

The delimiter you choose must match what the unflatten tool expects. If any of your object keys themselves contain a dot, a dot delimiter will produce ambiguous flat keys that cannot be unflattened correctly. In that case, pick a character that does not appear in your keys — an underscore, a slash, or a custom separator. Bracket notation for arrays (roles[0] instead of roles.0) is more widely recognised by third-party unflatten libraries and is the safer default when round-tripping to another tool.

Worked example with arrays and nesting

A more complex input:

{
  "server": {
    "host": "db.example.com",
    "port": 5432
  },
  "features": ["search", "export"]
}

Flattened with dot delimiter and dot array indices:

{
  "server.host": "db.example.com",
  "server.port": 5432,
  "features.0": "search",
  "features.1": "export"
}

With bracket array notation:

{
  "server.host": "db.example.com",
  "server.port": 5432,
  "features[0]": "search",
  "features[1]": "export"
}

Both forms preserve every leaf value exactly; only the key syntax differs.