Developer and Text Tools

How to Flatten Nested JSON into Dot Notation and Back

Flatten nested JSON into dot or bracket keys for spreadsheets, i18n and config files, rebuild it from flat keys or CSV headers and avoid separator clashes.

Saizul Amin
Saizul Amin3 Nov 2026 · 3 min read
How to Flatten Nested JSON into Dot Notation and Back

Nested JSON mirrors how programs think: an order has a customer, the customer has an address, the address has a city. Spreadsheets, translation platforms, search indexes and environment variables think in flat names instead. Flattening bridges the two, and unflattening brings the structure back. This guide shows how both work and what to watch for.

What flattening produces

Flattening walks every branch of the document and writes each leaf value under its full path. The order

{ "customer": { "address": { "city": "Chattogram" } }, "items": [ { "sku": "TEA-250" } ] }

becomes two flat keys: customer.address.city and items.0.sku. The dot is only a convention. Environment variables often use a double underscore, as in CUSTOMER__ADDRESS__CITY, and some tools prefer slashes. Array positions can be written as plain numbers or in brackets, such as items[0].sku, which many JavaScript libraries understand.

Where flat keys are used

  • Translation files. Platforms often store checkout.button.pay instead of nested objects.
  • Spreadsheets. Each path becomes a column, so a person can edit values without touching braces.
  • Configuration. Twelve-factor apps read nested settings from flat environment variables.
  • Search and analytics. Many indexes need flat field names for filters and facets.

Rebuilding the structure

Unflattening splits each key on the separator and creates objects along the way. Numeric parts usually mean array positions, so items.1.sku creates an array with two elements. Sometimes numbers are really IDs, such as users.1042.name, and should stay object keys; a good tool lets you choose.

The separator clash

The one real trap is a key that already contains the separator. If your data has a key called x.y and you flatten with dots, the flat key x.y could mean a member called x.y or a member y inside x. Unflattening cannot know. The fix is either a different separator or bracket style, where awkward keys are quoted, for example ["x.y"].

Doing it in the browser

The JSON Flattener and Unflattener has four modes.

  1. Flatten turns one nested document into a flat object. Choose the separator, the array index style, an optional depth limit and whether to keep empty objects and arrays.
  2. Unflatten takes a flat object and rebuilds the nested one, with numeric parts as array indexes unless you switch that off.
  3. JSON array → CSV flattens every record of an array and creates the union of all columns. Records with an extra field get their own column rather than losing it. You can download CSV or an Excel file with a frozen header.
  4. CSV → nested JSON reads a sheet whose headers are paths and rebuilds the records, converting numbers, true and false and empty cells when you ask it to.

The Reverse button sends the output back through the opposite mode, which is the fastest way to check that nothing was lost. When the tool sees separator clashes it names the affected keys so you can change the style before going further.

A worked example

Take an order with a customer, an address, two items and an empty notes list. Flattening with dots gives twelve keys, such as customer.address.zip and items.1.price, plus notes with an empty array, kept so the round trip is exact. For a spreadsheet of customers, two records with contact details and tags become the columns id, name, contact.email, contact.phone, tags.0 and tags.1. A colleague can fill in the missing phone number in Excel, and CSV to nested JSON turns the sheet back into proper objects.

Tips

  • Decide on one separator per project and document it.
  • Use a depth limit when only the first levels matter; deeper parts stay as JSON in one cell.
  • Keep long numeric strings, such as phone numbers, as text; values of more than fifteen digits are not converted to numbers.
  • Remember that the shape changes, not the values. Dates, currencies and text stay exactly as they were.

Summary

Flattening is a simple idea with one sharp edge. Pick a separator that never appears in your keys, keep empty containers when you need an exact round trip, and use reverse conversion to prove that the data survived.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages