JSON Flatten & Unflatten

Nested JSON Input
1
Delimiter
Flat JSON Output

Last updated:

Jsonic's JSON Flatten tool converts a nested JSON object into a flat key-value map using dot notation by default. A nested path like {"user":{"address":{"city":"Paris"}}} becomes {"user.address.city":"Paris"}. Arrays are indexed numerically: tags[0] becomes "tags.0". The Unflatten mode reverses the process: it reconstructs a nested object from a flat map. You can customize the key delimiter — use "/" for path-style keys or "_" to produce identifiers. All processing runs in your browser with no data upload.

How to flatten or unflatten JSON

  1. Select mode: Flatten (nested → flat) or Unflatten (flat → nested).
  2. Paste your JSON into the left panel, or click Example.
  3. Optionally change the delimiter (default: ".").
  4. Click Flatten or Unflatten.
  5. Copy the result from the right panel.

FAQ

What does JSON flattening do?

Flattening converts a deeply nested JSON object into a single-level map where each key is the full path to a leaf value. For example, {"a":{"b":1}} becomes {"a.b":1}. This is useful for working with databases that do not support nested types, generating dot-notation config keys, or processing JSON in environments that only handle flat key-value pairs.

What is the difference between flatten and unflatten?

Flatten converts nested JSON → flat dot-notation map. Unflatten is the inverse: it takes a flat map and reconstructs the nested object. You can round-trip a JSON object: flatten it, modify the flat keys, then unflatten to get the updated nested structure.

How are arrays handled when flattening?

Array elements are indexed numerically. An array ["a","b"] at key "tags" becomes "tags.0":"a" and "tags.1":"b". When unflattening, keys with numeric path segments are reconstructed as arrays.

Can I use a custom delimiter?

Yes. The default delimiter is ".". You can change it to "/" for URL-style paths, "__" for environment variable names, or any other string. The delimiter affects both flatten and unflatten — use the same delimiter for both directions.

What is JSON flattening used for?

Common use cases: inserting JSON data into relational databases as columns; comparing two JSON objects at the key level; generating environment variables from a config file (MY_DB_HOST from {"my":{"db":{"host":"..."}}}) using "_" delimiter; and working with Elasticsearch field mappings or Prometheus label extraction.

Can it flatten JSON arrays at the top level?

Yes. If the root is an array, each element is indexed by its position. An array [{}, {}] produces keys "0.field" and "1.field". Unflatten handles numeric root keys back to arrays.

Is there a size limit?

No hard limit. The tool runs in your browser using JavaScript and can handle large JSON files as long as your browser has enough memory. For very large files (>10 MB), consider using the jq command-line tool with the leaf_paths and getpath functions instead.