JSON Flatten / Unflatten

Flatten nested JSON into dot/bracket-notation keys, or unflatten those keys back into nested JSON.

Mode:
Input (nested JSON)
Loading editor…
Flattened Output
Loading editor…
Size: 0 bytesLines: 0

Related Tools

Learn more about the JSON Flatten / Unflatten

Flatten and Unflatten JSON

Flatten turns a nested JSON document into a single-level object, one key per leaf value. Nested object keys are joined with a delimiter (a dot, ".", by default), and array items get bracket notation — so data.items[0].sku means "the sku field of the first item in data.items".

Unflatten is the reverse: it parses those dot/bracket-notation keys back into the original nested structure, rebuilding objects and arrays exactly as they were.

The delimiter is configurable — use a slash, double colon, or any short string instead of the default dot, which matters if your data's own keys happen to contain dots. Both directions run entirely in your browser; paste JSON or drag and drop a .json file.

Why Flatten JSON?

Spreadsheet Exports

Spreadsheets and BI tools work with flat rows and columns. Flattening nested JSON into dot-notation keys turns it into something a spreadsheet can represent directly, and pairs naturally with the JSON to CSV converter.

Environment Variables

Env var systems and .env files only support flat key-value pairs. Flattening a nested config into keys like DATABASE.HOST or database.host is a common step before generating one.

Search Indexing

Some search indexes and key-value stores index flat fields more easily than deeply nested documents. Flattening exposes every leaf value as its own indexable field.

Diffing Deeply Nested Documents

A flat key-value list is often easier to diff line-by-line than deeply nested JSON, since each change shows up as a single changed key instead of a change buried several levels deep.

Example

Every leaf value becomes its own key. Object nesting is joined by the delimiter; array items are addressed by index in brackets. Unflattening the output on the right reproduces the JSON on the left exactly.

Nested
{
  "status": 200,
  "data": {
    "id": "ord_9F3K2",
    "total": 42.5,
    "items": [
      { "sku": "A1", "qty": 2 },
      { "sku": "B7", "qty": 1 }
    ]
  }
}
Flattened
{
  "status": 200,
  "data.id": "ord_9F3K2",
  "data.total": 42.5,
  "data.items[0].sku": "A1",
  "data.items[0].qty": 2,
  "data.items[1].sku": "B7",
  "data.items[1].qty": 1
}

Features

Flatten Nested JSON

Turn arbitrarily nested objects and arrays into single-level dot-notation keys, with bracket notation for array indices.

Unflatten Back to Nested

Parse flat keys like "data.items[0].sku" back into the original nested structure.

Configurable Delimiter

Use ".", "/", "::", or any short string as the key delimiter instead of the default dot.

Upload a File

Drag and drop or upload a .json file to flatten or unflatten it directly, no copy-pasting required.

Copy

Copy the result to your clipboard with a single click.

Download

Save the result as a standalone .json file for use in your project.

How to use

Paste your input in the left editor. The output appears automatically on the right. Use the toolbar buttons to copy, download, or transform the result.

  1. Paste or type your content in the input editor on the left.
  2. The formatted output is generated automatically.
  3. Use Copy, Download, or other actions from the output toolbar.
  4. Click the expand icon to view the output in fullscreen.
FAQ

Is this JSON flatten/unflatten tool free?

Yes, it is completely free to use with no limits, signup, or account required.

Is my JSON data uploaded to a server?

No. Both flattening and unflattening run entirely in your browser using JavaScript, whether you paste JSON or upload a file. Your data never leaves your machine.

What does "flatten" mean here?

Flattening turns a nested JSON document into a single-level object with one key per leaf value. Nested object keys are joined with a delimiter (a dot by default), e.g. "data.items[0].sku", and array items use bracket notation for their index.

Does unflatten restore the exact original structure?

Yes. Unflatten parses the dot/bracket-notation keys back into the same nested objects and arrays, including empty objects and arrays, so flatten followed by unflatten reproduces the original JSON.

Can I change the delimiter?

Yes. The default is a dot (.), but you can use any short string — a slash, double colon, underscore, etc. — as long as you use the same delimiter for both flattening and unflattening a given document.

What happens if one of my keys already contains the delimiter?

The tool warns you when a key in your data already contains the chosen delimiter or a literal "[", since that makes the flattened key ambiguous to unflatten correctly. Switching to a delimiter that doesn’t appear in your keys avoids this.

How are arrays handled?

Array items are addressed by their index in brackets, e.g. "tags[0]", "tags[1]". An empty array or object is kept as-is rather than dropped, so it round-trips correctly.

Can I upload a file instead of pasting JSON?

Yes. Drag and drop a .json or .txt file onto the input panel, or click the upload icon in the panel header to browse for one. Files up to 5MB are supported.

Why would I need to flatten JSON?

Common cases are preparing nested JSON for a spreadsheet export, generating environment variables from a nested config, indexing documents in a search engine, or making deeply nested documents easier to diff line-by-line.