Tool 42 / 50

JSON Unflattener

Reconstruct hierarchical nested JSON objects and arrays from flat dot-notated or bracket-delimited key-value dictionaries.

FLATTENED JSON INPUT
RECONSTRUCTED NESTED OUTPUT

What is a JSON Unflattener?

A JSON Unflattener is a reverse data restructuring utility that transforms single-level key-value dictionaries containing compound delimited keys (such as user.contact.email or items[0].name) back into deeply nested, multi-tiered hierarchical JSON object trees and arrays.

When JSON data is flattened for relational database storage (SQL rows), spreadsheet exports (CSV, Excel), or flat configuration formats (.env, properties files), structural nesting is collapsed into compound string path keys. The unflattener splits these compound keys along a designated separator, creates intermediary object branches on demand, reconstructs zero-indexed sequential lists into native arrays ([ ... ]), and restores the original tree topology.

Why Software Developers & Data Engineers Need JSON Unflattening

Reconstructing nested JSON is a fundamental requirement in data engineering workflows:

Step-by-Step Unflattening Example

The following real-world example demonstrates how a flattened dot-notated dictionary with bracket array indices is restored into a multi-tiered hierarchical JSON document.

Input: Flattened Dot-Notation Key-Value Object

{
  "id": 10842,
  "user.name.first": "Alexander",
  "user.name.last": "Hamilton",
  "user.contact.email": "alex@treasury.gov",
  "user.contact.phones[0]": "+1-202-555-0143",
  "user.contact.phones[1]": "+1-202-555-0199",
  "settings.notifications.email": true,
  "settings.notifications.sms": false
}

Output: Reconstructed Hierarchical Nested JSON Tree

{
  "id": 10842,
  "user": {
    "name": {
      "first": "Alexander",
      "last": "Hamilton"
    },
    "contact": {
      "email": "alex@treasury.gov",
      "phones": [
        "+1-202-555-0143",
        "+1-202-555-0199"
      ]
    }
  },
  "settings": {
    "notifications": {
      "email": true,
      "sms": false
    }
  }
}

Array Reconstruction & Path Splitting Mechanics

Our unflattening algorithm resolves core data structure challenges:

  1. Numeric Index Detection: Whenever a key path segment consists entirely of integer digits (e.g. phones.0 or phones[0]), the parent branch is instantiated as a native JavaScript Array ([]) rather than a generic object ({}).
  2. Mixed Delimiter Support: Intelligently normalizes bracket notation (items[0].price) alongside dot notation (items.0.price).
  3. Deep Branch Traversal: Recursively creates intermediate branch nodes on the fly without overwriting sibling keys sharing the same namespace prefix.
  4. Type Preservation: Preserves original primitive types (numbers, booleans, nulls, strings) without unintended string coercion.

Programmatic JSON Unflattening in Production

If you need to unflatten JSON programmatically inside backend microservices:

Resolving Primitive vs. Container Overwrite Conflicts

A common problem in unflattening corrupt data occurs when a key is declared both as a primitive value and as a nested parent container:

{
  "config.database": "postgres",
  "config.database.host": "localhost"
}

Our unflattener handles these structural collisions gracefully by upgrading primitive string values into container objects or assigning them to distinct nested branches without crashing the JSON parser.

Sparse Array Indexing vs. Dense List Allocation

When flattened keys have non-contiguous numeric indices (such as tags.0 and tags.5):

MongoDB `$unwind` & Aggregation Pipeline Inverses

In database analytics, MongoDB's $project and $group aggregation stages produce flattened key metrics. Unflattening allows data teams to reconstruct full entity documents prior to caching in Redis or pushing to client frontend applications.

100% Client-Side Privacy & Air-Gapped Security Guarantee

Reconstructing flattened database exports containing customer records, private authentication configurations, or financial ledgers demands complete security. Uploading flat data to cloud websites creates severe data breach risks.

JSON Empire guarantees total browser isolation:

Frequently Asked Questions

What happens if a flattened key path contains array brackets like `items[0]`?

The parser automatically normalizes bracket indices into array elements, producing clean JSON arrays ("items": [...]).

Can I reverse nested JSON back into a flat dictionary?

Yes. Use our companion tool JSON Flattener (Tool 41) to collapse nested object trees into single-level key-value pairs.

How can I download the unflattened JSON file?

Click the "💾 Download .json" button in the workspace panel to save a standalone JSON file directly to your disk.