Command Palette

Search for a command to run...

JS

JSON Flattener

Flatten nested JSON into single-level dot-notation keys, or unflatten dotted keys back into nested objects and arrays. Lossless round trip. 100% client-side.

What is a JSON Flattener?

A JSON flattener converts a nested JSON object into a single-level object whose keys are the full path to each value, so {"user":{"city":"Austin"}} becomes {"user.city":"Austin"}. Arrays flatten the same way, using the index as a path segment: {"roles":["admin","editor"]} becomes {"roles.0":"admin","roles.1":"editor"}. The result is a flat map of path to leaf value with no remaining nesting.

Flattening is how you get deeply nested API responses and config files into formats that only understand flat key-value pairs. Spreadsheet columns, environment variables, dotted i18n message keys, feature-flag stores, and many logging and analytics pipelines all expect one level of keys, and a dotted path such as user.address.city is the standard way to carry the original structure through them. The reverse operation, unflatten, rebuilds the nested object and its arrays from those dotted keys, so the transform is a lossless round trip in both directions.

This tool runs entirely in your browser. It parses the JSON, walks it to leaf values, and serialises the flat or nested result without sending anything to a server. Nothing is uploaded, logged, or stored, which keeps payloads with tokens, IDs, or personal data on your machine, and the tool keeps working offline once the page has loaded.

Flattening trades structure for a shape that spreadsheets, form encoders and environment variables can carry, and the round trip is lossless in both directions provided one thing holds: your keys must not already contain the delimiter. A key named "user.name" flattened with a dot is indistinguishable from a nested object, and unflattening will turn it into one. Change the delimiter to something the data does not use when that is a risk. Array indices become numeric path segments, so items.0.id addresses the first element, and an unflattener has to decide whether a numeric key means an array or an object with numeric keys. Empty objects and empty arrays are preserved explicitly rather than dropped, since losing them would change the meaning of a config file.

How to use the JSON Flattener?

  1. Choose flatten or unflatten

    Flatten turns nested JSON into dotted keys. Unflatten rebuilds nested objects and arrays from dotted keys. Load the sample to see both directions.

  2. Paste your JSON

    Paste a nested object to flatten, or a flat object with dotted keys to unflatten. The input must be valid JSON; parse errors are reported with the exact position.

  3. Set the key style

    Pick the delimiter, usually a dot, and choose dot (roles.0) or bracket (roles[0]) notation for array indices. Keep the same settings for both directions so the round trip matches.

  4. Copy or download the result

    Press the action button, then copy the output to your clipboard or download it as a .json file. The key count confirms how many leaves were produced.

Key Features

  • Lossless flatten and unflatten

    Flatten a nested object, then unflatten the result, and you get the original back, including arrays, nulls, booleans, and empty containers. The two operations are exact inverses.

  • Array-aware paths

    Array items keep their index in the path, so order survives the round trip. Choose dot notation (items.0.id) or bracket notation (items[0].id) to match the system you are feeding.

  • Configurable delimiter

    Use a dot by default, or switch to another separator when your target keys already contain dots. The same delimiter drives both flatten and unflatten.

  • Empty containers preserved

    An empty object or empty array is kept as a leaf value rather than silently dropped, so a config that relies on an empty list still round-trips correctly.

Frequently Asked Questions

Flattening JSON converts a nested object into a single-level object whose keys are the path to each value. The nested {"user":{"city":"Austin"}} becomes the flat {"user.city":"Austin"}. Every leaf value gets one dotted key, and no nesting remains in the output.

Comments

0 comments

0/2000 characters

No comments yet. Be the first to share your thoughts!

json flattenerflatten jsonflatten nested jsonunflatten jsonjson dot notationjson to flatnested json to flatjson path keysflatten json object