JSON Flatten / Unflatten

Turn nested JSON into flat key paths, or rebuild nested JSON from flat keys

Flatten nested JSON online into simple dot-notation key paths, or unflatten flat keys back into nested JSON objects. This is useful for converting JSON to CSV, storing settings in key-value databases, and comparing complex API responses. The free JSON flatten and unflatten tool makes deeply nested data easier to work with.

The result will appear here.
Press Ctrl+Enter or click the convert button.

About JSON Flatten / Unflatten

This tool converts deeply nested JSON into a single-level object whose keys are full paths such as user.address.city, and converts such flat objects back into the original nested structure. The conversion runs entirely in your browser, so your data is never uploaded.

Nested JSON is the natural format for APIs and configuration files, but many systems expect a plain list of key and value pairs. Spreadsheets, CSV exports, environment variables, translation files, search indexes and key-value stores cannot represent an object inside an object. Flattening solves this by joining every level of the hierarchy into one key, so { "user": { "address": { "city": "Paris" } } } becomes a single entry named user.address.city. Unflattening reverses the process and rebuilds the original structure, which makes the tool useful for round trips between a flat format and a nested one.

Key Features

  • Both directions — flatten nested JSON or unflatten flat keys, and swap the output back into the input with one click.
  • Delimiter choice — pick dot, hyphen, underscore, double underscore, hash, greater-than or slash.
  • Array styles — write indexes as items[0] or items.0.
  • Empty values — optionally keep empty objects and arrays so they survive a round trip.
  • Private and fast — nothing is sent to a server, so confidential payloads such as configuration or customer records stay on your device.
  • Clear errors — invalid JSON and conflicting keys are reported with a message that names the problem, instead of producing broken output.
  • Upload and download — load a .json or .txt file, then copy the result or save it as a file.

How to Use

  1. Choose Flatten or Unflatten.
  2. Paste or upload your JSON.
  3. Adjust the delimiter and array style if needed.
  4. Click the convert button or press Ctrl+Enter, then copy or download the result.

Example

{ "user": { "name": "Jane", "tags": ["a", "b"] } } flattens to { "user.name": "Jane", "user.tags[0]": "a", "user.tags[1]": "b" }. Choosing the underscore delimiter and the items.0 array style would instead produce keys such as user_name and user_tags_0. Pasting the flat result back in and switching to Unflatten with the same settings returns the original document.

Notes

  • When unflattening, numeric path segments create arrays and all other segments create objects.
  • Use the same delimiter and array style for unflattening that were used when flattening.
  • Keys that conflict, such as a as a value and a.b as a path, are reported as errors.
  • If a real key already contains the delimiter, for example "first.name", choose a different delimiter so the path can be split correctly when unflattening.
  • Values keep their JSON types. Numbers, booleans and null are not converted to strings.
  • Unflattening rebuilds structure from the keys only, so keys that were never produced from nested data are simply turned into nested objects.

Use Cases

  • Preparing nested data for CSV export, spreadsheets or key-value stores.
  • Building translation files and environment-style configuration from nested settings.
  • Comparing two JSON documents field by field.
  • Mapping API responses to database columns or form fields, where each flat key corresponds to one field.
  • Converting application settings to flat environment variables or properties-style configuration, and back again.
  • Inspecting very large documents, where a flat list of paths is easier to search than a deep tree.

Why Flatten JSON?

A flat structure is easier to search, sort, diff and store. Finding every value that sits under a given path becomes a simple text search, and two documents can be compared line by line without walking their trees. Flat keys also map directly onto tabular formats, which is why flattening is the usual first step before exporting JSON to a spreadsheet. The trade-off is that the structure is no longer visible at a glance, so it is best to keep the nested version as the source of truth and flatten only when a destination requires it.

Related Developer Tools

Tidy your data with the JSON Formatter, or convert it with the JSON to CSV converter, the JSON to YAML converter or the JSON Schema Generator.

Frequently Asked Questions

Is my JSON sent to a server?

No. Everything is processed locally in your browser.

Can I flatten a root array?

Yes. Keys are then indexes such as [0].name or 0.name.

Why did an empty object disappear?

Enable Keep empty {} / [] so empty containers are preserved as values.

Will unflattening always restore my original JSON?

Yes, as long as you use the same delimiter and array style, and empty objects and arrays were kept when flattening. Without that option, empty containers have no keys and cannot be restored.

Which delimiter should I choose?

The dot is the most common choice. Use a different one, such as a slash or double underscore, when your keys already contain dots.

Is there a size limit?

There is no fixed limit because the work happens in your browser. Very large files depend on your device's memory.