JSON Object Unflattener

Parses a flat object of dot/bracket path keys (e.g. { "a.b[0].c": 1 }) and reconstructs the equivalent nested JSON object or array, the exact inverse of the JSON Object Flattener. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-27

Overview

Introduction

Flattening JSON into dot/bracket path keys is great for diffing and spreadsheet export, but the result isn't the shape most code or APIs expect. This tool takes it back the other way, rebuilding proper nested JSON from a flat object of path keys.

It's built as the direct inverse of this site's JSON Object Flattener, reading the exact a.b[0].c path syntax that tool produces.

What Is JSON Object Unflattener?

A reconstructor that parses each key in a flat JSON object into an ordered sequence of path segments, dotted names for object properties and bracketed numbers for array indices, and uses those segments to rebuild the equivalent nested object or array.

Every flat key's value is assigned at exactly the nested location its path describes, so containers are rebuilt implicitly as their child paths are processed, not declared up front.

How JSON Object Unflattener Works

The input is parsed as JSON and must be a top-level object; each of its keys is then split into segments by scanning for . separators and [N] bracket groups in order.

Starting from an empty root, each key's segments are walked in sequence: a bracket segment indexes into (and lazily creates) an array at that position, a dotted segment indexes into (and lazily creates) an object property, and the final segment in the path assigns the flat value itself.

Once every key has been applied, the resulting nested structure is serialized back to indented JSON.

When To Use JSON Object Unflattener

Use it to reverse a JSON Object Flattener export back into normal nested JSON for an API, config file, or codebase that expects proper structure.

It's also useful for reconstructing JSON from any other source that emits dot/bracket path-keyed data, spreadsheet exports, some logging formats, or flat config stores.

Features

Advantages

  • Reconstructs both nested objects and arrays correctly by reading the bracket-vs-dot syntax already present in each path.
  • Handles arbitrarily deep nesting and mixed object/array paths (a.b[0].c) in a single pass.
  • Preserves array index positions exactly, including gaps, rather than silently compacting them.
  • Reports a specific error message when a path segment is malformed (an unterminated bracket, a non-numeric index, an empty segment).

Limitations

  • Only reconstructs from the exact dot/bracket path syntax the JSON Object Flattener produces; a differently formatted flat-key convention (like double underscores) needs its own tool.
  • A flat object whose keys imply conflicting structures at the same path (e.g. both a.b and a.b[0]) will produce output reflecting whichever key was processed last, since object keys have no guaranteed conflict-resolution rule beyond source order.
  • The top-level input must be a JSON object of path keys; it can't be a bare array or scalar, even if the reconstructed value underneath will itself be one.

Examples

Rebuilding a nested object with an array

Input

{
  "user.name": "Ada",
  "user.address.city": "London",
  "roles[0]": "admin",
  "roles[1]": "editor"
}

Output

{
  "user": {
    "name": "Ada",
    "address": {
      "city": "London"
    }
  },
  "roles": ["admin", "editor"]
}

Dotted segments rebuild the nested user.address object, while bracketed segments rebuild the roles array in order.

Best Practices & Notes

Best Practices

  • Feed this tool output produced by the JSON Object Flattener (or an equivalent a.b[0].c-style source) for a guaranteed clean reconstruction.
  • Check for gaps in array indices in your source data; missing indices become explicit null entries in the rebuilt array rather than being skipped.
  • Run the result through the JSON Formatter or JSON Validator afterward if you need to confirm the reconstructed shape matches what a downstream system expects.

Developer Notes

Path parsing is a small hand-written scanner (parseSegments) that walks each key character by character, distinguishing a [N] bracket segment (must be all digits) from a dotted name segment; reconstruction (setPath) recurses down each segment list, using Array.isArray checks to decide whether to build/extend an array or an object at each level, so no upfront schema or path list is needed. This deliberately mirrors flatten-json-object.ts's own key-building convention (prefix ? `${prefix}.${key}` : key for objects, `${prefix}[${index}]` for arrays) so encode/decode stay symmetric.

JSON Object Unflattener Use Cases

  • Reversing a JSON Object Flattener export back into normal nested JSON for use in an API or application.
  • Reconstructing structured JSON from flat, path-keyed data exported from a spreadsheet or logging pipeline.
  • Rebuilding a nested config file from a flat key-value store that used dot/bracket path naming.

Common Mistakes

  • Feeding in a flat-key format that isn't dot/bracket notation (e.g. double-underscore-separated keys); only the a.b[0].c convention is understood.
  • Passing a top-level JSON array instead of an object of path keys; the flattened representation is always an object, even when the original value was an array.
  • Expecting sparse array indices to compact automatically; gaps are preserved as null entries instead.

Tips

  • If reconstruction looks wrong, check for typos in bracket indices, a non-numeric value inside [...] is rejected with a specific error.
  • Pair this with the JSON Object Flattener to round-trip a document, flatten for diffing or export, then unflatten to restore its original shape.
  • Use Properties to JSON instead if your flat data uses Java-style dotted .properties syntax rather than a flattener's bracket-index arrays.

References

Frequently Asked Questions