Nested JSON Flattener

Flatten deeply nested LLM JSON output into a dot-notation key-value map.

Free nested JSON flattener. Paste deeply nested JSON from a structured LLM response and get a flat key-value object using dot or bracket notation, with a configurable depth limit, all in your browser. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

What does flattening do to arrays?

Array elements become indexed path segments. In dot notation an element looks like items.0.name; in bracket notation it looks like items[0].name. Both point to the same value.

Flatten nested LLM JSON into flat keys

Structured LLM outputs and tool-call payloads nest objects inside arrays inside objects. That’s painful to map into a spreadsheet, a form, or a flat config. This tool turns any nested JSON into a single-level key-value map where each key is the full path to a leaf value — in either dot notation (a.b.0.name) or bracket notation (a.b[0].name) — with an optional depth limit.

When you need this

The most common scenario is a structured LLM response or function-call result that looks clean as JSON but is awkward to work with downstream. For example, a model might return:

{
  "user": {
    "name": "Alice",
    "address": {
      "city": "London",
      "postcode": "EC1A 1BB"
    }
  },
  "scores": [92, 87, 95]
}

Flattened, this becomes:

{
  "user.name": "Alice",
  "user.address.city": "London",
  "user.address.postcode": "EC1A 1BB",
  "scores.0": 92,
  "scores.1": 87,
  "scores.2": 95
}

Now every value is accessible by a single string key — ready to paste into a spreadsheet, diff against another response field by field, or map into a flat config format.

How flattening works

The flattener walks the JSON recursively. Whenever it hits a leaf — a string, number, boolean, null, an empty object, or an empty array — it records the accumulated path as a key and the leaf as the value. Non-empty objects and arrays are expanded: object keys are appended as path segments and array elements are appended as numeric indices. If you set a maximum depth, descent stops at that level and the remaining structure is kept intact as a JSON value, so nothing is lost. The result is one flat object you can read top to bottom.

Dot vs bracket notation

Both notations encode the same paths; the choice depends on what consumes them:

  • Dot notation (user.address.city) is readable and works in most template languages, config parsers, and spreadsheet formulas.
  • Bracket notation (user.address.city, scores[0]) is valid JavaScript accessor syntax and suits tools that evaluate path expressions dynamically.

Tips and examples

  • Use dot notation when you’ll feed the keys into tools that expect a.b.0 paths; use bracket notation when you want valid JavaScript-style accessors.
  • Flatten a tool-call arguments object to quickly diff two responses field by field.
  • Set a shallow depth (1 or 2) to get a high-level overview of a huge payload before drilling in with the JSON Pointer Extractor.
  • Empty containers are preserved as {} / [] so the flattened map round-trips the original structure faithfully.
  • Flatten two responses from the same prompt and compare keys side by side — a missing key in one response reveals a field the model inconsistently omits.
  • If you are feeding the result into a CSV, the flat key list becomes your header row directly — each path is a column name.