Flatten JSON

Flatten JSON Online

Collapse deeply-nested JSON into flat dot-notation key-value pairs, ready to map to spreadsheet columns or CSV.

1,000 free credits on signup · Deterministic — no AI model sees your JSON

Flatten JSON
Flatten in the editor
Input
Result

Flatten nested JSON into dot-notation keys in the full editor.

Runs entirely in your browser — nothing is uploaded.

{"user":{"id":42,"name":"Ada Lovelace","address":{"city":"London","zip":"EC1A"}},"orders":[{"id":"ord_1","total":29},{"id":"ord_2","total":18.5}]}
Flattening JSON converts a nested object or array into a single flat list of dot-notation keys paired with their values, for example user.address.city or orders[0].total. This makes deeply-nested data easy to map to spreadsheet columns, load into tools that expect flat input, or diff line by line. JSON Copilot's Flatten action is deterministic — plain code, not an AI guess — and runs in the full editor with a free account: your JSON goes only to JSON Copilot's own server, never to an AI model, and a run costs credits in proportion to property count — the exact credit estimate is shown on the button before you run — drawn from the 1,000 you get free on signup.

Nested JSON, flattened

Input — nested
{
  "user": {
    "id": 42,
    "name": "Ada Lovelace",
    "address": { "city": "London", "zip": "EC1A" }
  },
  "orders": [
    { "id": "ord_1", "total": 29 },
    { "id": "ord_2", "total": 18.5 }
  ]
}
Output — flat dot notation
{
  "user.id": 42,
  "user.name": "Ada Lovelace",
  "user.address.city": "London",
  "user.address.zip": "EC1A",
  "orders[0].id": "ord_1",
  "orders[0].total": 29,
  "orders[1].id": "ord_2",
  "orders[1].total": 18.5
}

Every leaf value becomes one key holding its full path. Objects join with a dot, array elements carry a bracketed index, and both documents hold the exact same values — only the shape changes.

How to flatten JSON

  1. 1

    Paste your nested JSON

    Drop raw or deeply nested JSON into the input panel, or load the built-in example to see how flattening behaves.

  2. 2

    Make sure it is valid

    Flattening needs parseable JSON, so the editor highlights the first syntax error with a line and column if the input will not parse.

  3. 3

    Run Flatten

    Open it in the editor and run Flatten to collapse every nested object and array into a single level of dot-notation keys.

  4. 4

    Read the flat key/value pairs

    Each entry is one leaf value with its full path, such as user.address.city or orders[0].total, so the whole document fits on flat rows.

  5. 5

    Copy or export

    Copy the flattened output to paste into a spreadsheet, .env file, or CSV, or keep exploring it in the tree and mind-map views.

Why flatten with JSON Copilot

Dot-notation keys

Nested paths collapse into readable keys like user.address.city.

Array-aware indexing

Array elements keep their position as items[0].sku, so order and structure survive.

Deterministic, not AI

Flattening is pure code on JSON Copilot's own server — your JSON is never sent to an AI model.

Spreadsheet and CSV ready

Flat key/value pairs map straight to columns for spreadsheets or CSV export.

1,000 free credits

Flatten costs credits based on property count — the exact estimate is shown before you run — and a free account starts with 1,000.

One editor, many views

The same editor also formats, validates, and renders tree and mind-map views of the data.

What is JSON flattening and dot notation?

Flattening rewrites a nested JSON document as a single flat object whose keys are the full path to each leaf value. Instead of walking through nested braces, you get one entry per scalar: a string key like user.address.city and the value that lives at that path. The depth that was expressed by nesting moves into the key names, so the document loses its levels but keeps every value.

The path syntax is called dot notation: each level of an object is joined to the next with a dot, so { "a": { "b": 1 } } becomes { "a.b": 1 }. It is the same convention many libraries already use to reach into nested data — Lodash's _.get(obj, 'a.b.c'), MongoDB's dotted field queries, and countless config systems all address nested values by path. Flattening simply materializes every one of those paths at once.

The transform is deterministic — the same input always produces the same output — and JSON Copilot runs it as plain code on its own server, so no AI model is involved and your JSON never reaches an LLM. It is lossless for values and, for plain object and array data, largely lossless for structure too: given the flat keys you can usually reconstruct the original nesting. The caveats to that round trip are covered below.

How arrays and indexes are notated

Objects nest by name, but arrays nest by position, so flattening records array elements with a bracketed index instead of a dot: orders[0].total, orders[1].total, and so on. The index is zero-based, matching JSON and JavaScript semantics, and it is appended directly to the key that holds the array. An array of objects therefore produces keys like items[0].sku and items[1].sku.

Nested arrays extend the same idea by chaining brackets: a two-dimensional matrix flattens to matrix[0][0], matrix[0][1], and matrix[1][0]. Mixed nesting — an array inside an object inside an array — reads left to right along the path, for example data.rows[2].cells[0]. Because every segment is explicit, no positional information is lost and the flat keys sort in a predictable order.

Empty containers are the one place implementations differ. A leaf that is an empty object {} or empty array [] has no scalar inside it to emit, so some flatteners drop the path entirely while others keep a single key mapped to the empty value. If preserving empty structures matters for your round trip, verify that behavior against your own data before relying on it.

Where flattening JSON is useful

The most common reason to flatten is tabular export. Spreadsheets and CSV files are inherently flat — one column per field — so a nested API response has to be collapsed before it fits. Flattening turns user.address.city into a column header and its value into the cell beneath it, letting you paste an array of records straight into Google Sheets or Excel.

Flat key/value pairs also map cleanly onto configuration and environment systems. Tools that read delimited keys — application.properties files, feature-flag stores, or key/value databases — accept a flattened document with little translation, and environment variables usually swap the dot for a double underscore, as in USER__ADDRESS__CITY. The same shape makes config diffing far easier: comparing two flat documents surfaces exactly which paths changed instead of a noisy diff over reindented nested blocks.

In analytics, flattening is a stepping stone to columnar storage. Warehouses such as BigQuery can query nested and repeated fields directly with UNNEST, but many pipelines still flatten JSON first so each path becomes its own typed column that is simple to select, filter, and aggregate. Flattened logs and events are likewise easier to index in search engines and to feed into tools that expect a single field per key.

Round-trip: unflattening and its caveats

Because the keys carry the full path, a flattened document can usually be expanded back into nested JSON: split each key on its dots and brackets, then rebuild the objects and arrays segment by segment. Value types survive the trip, so numbers stay numbers, booleans stay booleans, and null stays null — nesting is the only thing that changes.

The round trip is not always unambiguous, though. If an original object key literally contains a dot — {"user.name": "Ada"} — a naive unflattener reads it as two levels (user then name) and rebuilds the wrong shape. Keys that contain brackets, or numeric object keys that look like array indexes, create the same confusion, and sparse or reordered arrays can lose information when indexes are missing.

Types only survive as long as you stay in JSON. Exporting the flat result to CSV is a different matter: every value becomes text, so 42 and "42" are no longer distinguishable and null collapses to an empty cell. For that reason, treat flattening as a one-way transform for display and export, and keep the original nested JSON whenever you need a guaranteed, loss-free round trip.

Frequently asked questions

Is the JSON flattener free?

Signing up is free, and every new account gets 1,000 free credits. Flatten is a Copilot action that deducts credits based on how many properties your JSON has — the exact credit estimate is shown on the button before you run — so your 1,000 signup credits cover plenty of real payloads.

Is my data private?

Your JSON is posted only to JSON Copilot's own server, which runs the flatten as deterministic code — it is never sent to an AI model or any third party. Detected sensitive values like passwords, API keys, and emails are also masked on your device before the request (on by default), so they reach the server only as placeholders and those detected originals never leave your browser — detection is pattern-based, so give a quick glance to secrets under unusual field names. Only the AI features (explain and documentation) transmit data to a model, and the same on-device masking applies there.

Can it handle large files and work offline?

The Monaco-based editor is built for large documents, and credit cost simply scales with property count. Flattening itself runs on JSON Copilot's server, so you do need a connection and a signed-in account to run it.

How are arrays flattened?

Array elements are written with a zero-based bracketed index, like orders[0].total and orders[1].total, so both the order and the nesting are preserved in flat form.

What is the difference between dot notation and JSONPath?

Dot notation writes a bare path such as user.address.city, while JSONPath prefixes the root and uses the same idea as an expression, $.user.address.city. Flattening emits plain dot-and-bracket keys, not JSONPath queries.

Can I unflatten the result back to nested JSON?

Usually, yes: the dot-and-bracket keys can be split and rebuilt into the original objects and arrays. It is ambiguous only when an original key literally contains a dot or bracket, so keep the source if you need a guaranteed round trip.

What is the difference between flattening and minifying?

Minifying strips whitespace but keeps the nested structure intact, so the value is unchanged. Flattening removes the nesting itself, moving each path into the key name to produce a single level of key/value pairs.

Why will my JSON not flatten?

Flattening requires valid JSON, so it fails on trailing commas, single quotes, unquoted keys, or comments. The editor flags the first error with a line and column so you can fix it and try again.

Related tools

Flatten your JSON now

Open the Editor