ZapKit

Flatten & Unflatten JSON

Turn nested JSON into a single level of keys such as user.address.city, or rebuild nested objects and arrays from flat dotted keys.

What does flattening JSON mean?

Flattening converts nested JSON, objects inside objects and arrays, into a single object where each key is the full path to a value, such as user.address.city. The data is the same, but every value sits at one level.

Flat JSON is easier to compare, search and load into tools that expect simple key-value pairs: spreadsheets and CSV exports, Elasticsearch fields, i18n translation files, feature-flag systems and environment variables. Unflattening turns the dotted keys back into nested structures, which helps when an API or config loader expects the nested form.

How to use the Flatten

  1. 1.Paste JSON

    Any object or array, however deeply nested.

  2. 2.Choose flatten or unflatten

    Set the key separator and how array positions are written.

  3. 3.Copy the result

    Or download it as a .json file.

Example: a user record

A user with name and a nested address, a roles array with two values and an active flag:

user.name
"Asha"
user.address.city
"Pune"
roles.0 / roles.1
"admin" / "editor"
active
true
Keys
6

Four levels of nesting become six flat keys, and unflattening them restores the original object.

Paths you can read

Flattening walks the whole structure and writes one key per value, joining each level's name with the separator. Array items get their index, as roles.0 or, with brackets on, roles[0]. Empty objects and arrays are kept as values so nothing disappears.

Unflattening reverses it: keys are split on the separator, bracketed indexes are read as positions, and a numeric segment creates an array instead of an object. Flattening then unflattening returns the original structure.

Frequently asked questions

Why flatten JSON?

Flat keys map directly to spreadsheet columns, environment variables, translation files and search indexes.

Can I use a different separator?

Yes. Use _ or / or anything else, as long as it doesn't appear inside your key names.

Are arrays supported?

Yes. Each item gets its index in the path, and unflattening rebuilds the array.

What happens to null values?

They're kept as null under their full path.

More Developer tools