Skip to content
jsonforge.app

JSON Flatten

Flatten nested JSON to dot-notation keys or unflatten back to nested structure.

Loading editor…

Flattened JSON

Paste JSON to flatten into dot-notation keys.

O que é JSON Flatten?

A JSON flatten/unflatten tool transforms between nested and flat JSON structures. Flattening converts deeply nested objects into a single-level object with dot-notation keys (e.g., user.address.city becomes user.address.city or user[0].address.city for arrays). Unflattening reverses this process, reconstructing the original nested structure from dot-notation keys. This is useful for data processing, API transformations, converting hierarchical data to tabular formats, or when you need to query nested properties with simple key lookups. Arrays are preserved with bracket notation — user.tags[0] refers to the first element of the tags array. The tool shows depth reduction statistics, so you can see how much complexity is removed or restored.

Como usar JSON Flatten

  1. Paste your nested JSON into the left panel for flattening, or flat JSON for unflattening.
  2. Switch between Flatten and Unflatten modes using the toggle button.
  3. Flattened output uses dot notation (.) for nested objects and bracket notation ([]) for arrays.
  4. Unflattening reconstructs the original structure from dot-notation keys.
  5. Statistics show original depth, flattened depth, and total key count.

Exemplos

Nested object → Flattened

Entrada

{ "user": { "name": "Alice", "address": { "city": "San Francisco", "zip": "94102" } } }

Saída

{ "user.name": "Alice", "user.address.city": "San Francisco", "user.address.zip": "94102" }

Array → Flattened with brackets

Entrada

{ "users": [ { "name": "Alice", "role": "admin" }, { "name": "Bob", "role": "user" } ] }

Saída

{ "users[0].name": "Alice", "users[0].role": "admin", "users[1].name": "Bob", "users[1].role": "user" }

Erros comuns

  • Assuming flattened keys lose type information — flattened keys are strings (e.g., user.address.city), but the associated values retain their original types. Numbers, booleans, null, objects, and arrays are all preserved correctly.
  • Thinking unflattening can reverse arbitrary key collisions — if flattening creates key collisions (e.g., both a.b and a['b'] mapping to the same flattened key), unflattening can't restore both originals. Use consistent property naming in your source JSON to avoid this.
  • Expecting sorting or ordering in flattened output — flattened keys appear in first-seen order from a depth-first traversal. The order is deterministic but not alphabetical (a.b.c comes before a.b.d because we visit property c before d, not because of alphabetical sorting).

Por que usar esta ferramenta

  • Bidirectional conversion — flatten nested JSON to a single level, then unflatten back to the original structure. Statistics show depth reduction and key count.
  • Array preservation — bracket notation (users[0].name) preserves array structure, making it easy to reference specific elements or reconstruct the original arrays.
  • Simple query access — flattened JSON lets you access any nested property with a single key lookup, with no nested loops or recursive traversal needed.

Perguntas frequentes