JSON Object Flattener

Converts every nested object and array into a single-level object keyed by its full path (a.b[0].c), useful for diffing, spreadsheet export, or any system that only understands flat key-value pairs. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-22

Overview

Introduction

Deeply nested JSON is great for representing structure but awkward for tasks that just want a flat list of every value and where it lives, diffing two documents, exporting to a spreadsheet, or building a simple key-value config.

This tool collapses arbitrary nesting into one flat object, with each original value's location encoded directly in its key.

What Is JSON Object Flattener?

A flattener that recursively walks a JSON object or array and produces a single-level object where every key is the full dot/bracket path to a leaf value (e.g. user.address.city or roles[0]).

Only leaf values, strings, numbers, booleans, null, and empty objects/arrays, appear as values in the output; every container is expanded into its path instead.

How JSON Object Flattener Works

The tool recursively descends into the input, appending .key for object properties and [index] for array items to build up each path, and continues recursing until it reaches a scalar or an empty container.

Once a leaf is reached, the accumulated path becomes the flat object's key and the leaf value is assigned directly, with no further transformation.

When To Use JSON Object Flattener

Use it before diffing two JSON documents, since a flat structure makes line-by-line comparison tools far more effective than nested JSON.

It's also useful for exporting a JSON document's leaves into a simple key-value config or spreadsheet-friendly format.

Features

Advantages

  • Makes deeply nested structures diffable and scannable at a glance.
  • Distinguishes array indices from object keys via bracket vs. dot notation.
  • Preserves empty objects and arrays as explicit leaf values rather than dropping them.

Limitations

  • There's no built-in tool to reverse the flattening back into nested JSON.
  • Very large or deeply nested documents can produce a large number of long, unwieldy keys.

Examples

Flattening nested data

Input

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

Output

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

Each nested value's full path becomes its key in the flat output object.

Best Practices & Notes

Best Practices

  • Use this before running a generic text diff tool on two similar JSON documents for a much more readable comparison.
  • For spreadsheet export of an array of records, JSON to CSV is usually a better fit than flattening a single object.
  • Keep the original nested JSON around if you'll need to reconstruct the structure later.

Developer Notes

The recursive flatten() function distinguishes arrays from objects explicitly (rather than treating both as generic key iteration) so that array indices get bracket notation (roles[0]) while object properties get dot notation (user.name), keeping the two structurally distinct in the flattened key space rather than colliding on a shared notation.

JSON Object Flattener Use Cases

  • Preparing two JSON documents for a readable line-by-line diff
  • Exporting a JSON object's leaf values into a flat config format
  • Auditing exactly which paths exist in a deeply nested document

Common Mistakes

  • Expecting a built-in way to unflatten the result back into nested JSON automatically.
  • Flattening a very large document and getting an overwhelming number of keys; consider flattening a sub-object instead.
  • Confusing bracket-notation array keys with dot-notation object keys when writing code against the flattened output.

Tips

  • If you only need array items flattened (not object nesting), Flatten a JSON Array is a better fit.
  • Combine with Extract JSON Keys if you only need the list of paths, not their values.

References

Frequently Asked Questions