← Blog

Flatten JSON Online — Flatten & Unflatten

JSON formatter blog · Open JSON Formatter

Flattened JSON output using dot paths and array index paths
Flatten JSON Online — Flatten & Unflatten

To flatten JSON online, convert nested objects and arrays into path-based keys such as user.name and items[0].sku. JSON Formatter & Converter supports flatten and unflatten workflows in your browser, so you can prepare nested data for review, tables, CSV export, or debugging without signup.

What Flatten JSON Means

JSON can represent deep structures: objects inside objects, arrays inside objects, and arrays of objects. Flattening turns that nested structure into a single-level object where each key describes the path to the original value. Dot notation is commonly used for object keys, while bracket notation is commonly used for array positions.

For example, user.address.city points to a city nested under user and address. items[0].sku points to the sku field in the first item of an array. This path format is useful when you need to talk about exact locations in a document, export simpler rows, or compare values that are otherwise buried in a large payload.

Flattening is not only a format change; it is a way to make paths explicit. That can be useful even if you never export the result. A flattened copy gives reviewers a quick list of every reachable value and the path needed to find it in the original object.

How To Flatten JSON Online

  1. Open JSON Formatter & Converter.
  2. Paste valid JSON, import a local file, or use Import URL when CORS allows the remote content.
  3. Format or validate the input first if needed.
  4. Use the flatten action or Convert mode option for flattened JSON.
  5. Review the path keys, then copy or download the output.

Flattening depends on valid structure. If the document fails to parse, fix it with validate JSON online before flattening. If the document is large, inspect it first with the JSON tree viewer online.

After flattening, scan the output for paths that are longer or noisier than expected. Very long paths often point to deeply nested sections that may not fit a table cleanly. If the goal is CSV export, consider trimming the input to the array or object that represents the rows before flattening the whole response.

Flatten JSON Example

Nested input:

json
{
  "user": {
    "name": "Ada",
    "address": {
      "city": "London"
    }
  },
  "items": [
    {
      "sku": "book",
      "qty": 2
    }
  ]
}
{
  "user": {
    "name": "Ada",
    "address": {
      "city": "London"
    }
  },
  "items": [
    {
      "sku": "book",
      "qty": 2
    }
  ]
}

Flattened output:

json
{
  "user.name": "Ada",
  "user.address.city": "London",
  "items[0].sku": "book",
  "items[0].qty": 2
}
{
  "user.name": "Ada",
  "user.address.city": "London",
  "items[0].sku": "book",
  "items[0].qty": 2
}

The values are the same, but every nested location is represented by a single path key. That makes it easier to scan or search for exact fields in a complex document.

The output is still JSON. It is just a single-level object where paths carry the structure. That means you can format it, minify it, compare it with another flattened object, or convert it to a table-like format when the values are simple enough.

Dot Paths And Index Paths

Flattened JSON often uses two path styles together. Dot paths describe object properties: customer.email, billing.address.postalCode, or metadata.source. Index paths describe array positions:items[0], items[1].sku, or events[3].type.

Index paths are precise, but they also mean order matters. If the array is reordered, items[0] may refer to a different record. When the array represents rows, flattening can be useful. When it represents an unordered collection, consider whether you need to sort, filter, or reshape the data before comparing or exporting it.

Troubleshooting flattened JSON

If the flattened output contains too many columns, the input may include metadata, pagination, debug fields, or nested arrays that are not part of the table you want. Trim the JSON to the records you need, or inspect the Tree tab first so you can choose the right branch before flattening.

If unflattening produces a different shape than expected, look for keys that contain literal dots or brackets. Path notation uses those characters to describe nesting, but some real field names include them. There is no universal escaping rule across every system, so unusual keys may need manual cleanup.

If array paths create confusing output, check whether the array represents ordered positions or independent records. Flattening keeps indexes because they identify exact locations. For reporting or spreadsheet work, you may need to reshape the array into rows before converting to CSV.

Unflatten JSON

Unflattening reverses the process. A flat object with path keys becomes nested JSON again. This is useful when a spreadsheet, log tool, or configuration system gives you dotted keys and you need the original object structure back.

json
{
  "profile.name": "Ada",
  "profile.active": true,
  "roles[0]": "admin",
  "roles[1]": "editor"
}
{
  "profile.name": "Ada",
  "profile.active": true,
  "roles[0]": "admin",
  "roles[1]": "editor"
}

After unflatten:

json
{
  "profile": {
    "name": "Ada",
    "active": true
  },
  "roles": ["admin", "editor"]
}
{
  "profile": {
    "name": "Ada",
    "active": true
  },
  "roles": ["admin", "editor"]
}

Review unflattened output if path keys contain literal dots or brackets that are part of a field name rather than a path. Different systems use different escaping conventions, so unusual keys may need manual cleanup.

When Flattening Helps

Flattening helps when nested data needs to become easier to search, compare, or export. Support teams can point to a path in a bug report. QA teams can compare exact fields across fixtures. Developers can inspect webhook payloads without expanding every branch. Data teams can prepare a simpler shape before converting to CSV or TSV.

Flattening is especially helpful before converting JSON to CSV or TSV. CSV is a flat table, while JSON is nested. Flattened path columns make that difference explicit. For deeply nested arrays, you may still need manual reshaping because one JSON document can represent relationships that do not fit cleanly into one table.

Honest limits of flatten and unflatten

Flattening preserves values, but it can make relationships less obvious. A nested object shows which fields belong together. A flat object shows paths, which are easier to search but less expressive for grouped data. Use the flattened version for inspection, comparison, and table-style workflows, and keep the original nested JSON when structure matters.

Unflattening is also best-effort when path keys are ambiguous. A clean path like profile.name is straightforward. A key that literally includes a dot, bracket, or mixed convention may need manual interpretation. Review the result before using it as a source of truth.

Flatten Vs Tree View Vs Compare

Tree view, flatten, and compare all expose paths, but they are used at different moments. Tree view is for navigation. Flatten is for output. Compare is for changes between two versions. A practical workflow is to inspect the Tree tab, flatten the fields you care about, then compare or export the result.

If the finished output needs to be compact, use minify JSON online. If it needs to be embedded as text, use JSON stringify online. If it needs to move into an XML workflow, use convert JSON to XML.

Import URL And Privacy

Pasted JSON is flattened and unflattened in your browser. No account is required. If you use Import URL, your browser fetches the remote resource directly and the remote host must allow CORS. Tools Viewer does not proxy the remote response. For private documents, paste local text or open a local file and keep the result under your control.

Flattened output can expose more field names at once than the original nested document, so treat it with the same care as the source data. If you download or share the result, review whether paths reveal private attributes, IDs, or internal names that were less obvious in the nested view.

Related JSON Tasks

Flattening works well with JSON formatter online, compare JSON online, JSON size calculator, Python dict to JSON, and JSONL to JSON.

FAQ

Can I flatten JSON online for free?

Yes. JSON Formatter & Converter supports flattening JSON in the browser for free with no signup.

What path format does flattened JSON use?

Flattened output uses dot paths for object keys and bracket indexes for arrays, such as user.name and items[0].sku.

Can I unflatten JSON back to nested objects?

Yes. Use unflatten to turn path-based keys back into nested objects and arrays, then review the result.

Is flattening useful before CSV export?

Yes. Flattening can make nested fields easier to represent as flat CSV or TSV columns, though complex arrays may still need cleanup.

Does flattening change the values?

Flattening keeps the values but changes how their locations are represented, using path-based keys instead of nested objects and arrays.

Does flattening upload my JSON?

No. Pasted JSON is processed in your browser. Import URL fetches from your browser and requires CORS from the remote host.

Can keys with dots cause issues?

They can. If a literal key contains dots or brackets, review unflattened output because path notation may need manual adjustment.

Start with JSON Formatter & Converter or read the JSON Formatter guide. Related: validate JSON online, convert JSON to YAML and CSV, JSON tree viewer online, and JSON stringify online.