JSON Flatten

Flatten nested JSON objects to dot-notation keys and unflatten them back. Works with deeply nested objects and arrays.

Input
Output
 

How to Use JSON Flatten

1

Paste Your JSON

Paste any deeply nested JSON object or array into the input panel.

2

Choose Direction

Click "Flatten" to convert nested objects into flat dot-notation keys like "user.address.city". Click "Unflatten" to expand flat key-path objects back into nested JSON.

3

Copy the Result

The output appears on the right. Use the Copy button to grab it.

Examples

Before (Nested JSON)

{
  "user": {
    "name": "John",
    "address": {
      "city": "New York",
      "zip": "10001"
    }
  },
  "tags": ["admin", "editor"]
}

After (Flattened)

{
  "user.name": "John",
  "user.address.city": "New York",
  "user.address.zip": "10001",
  "tags[0]": "admin",
  "tags[1]": "editor"
}

Frequently Asked Questions

What does flattening JSON do?

Flattening converts nested JSON like {"user":{"name":"John","address":{"city":"NYC"}}} into a flat object with dot-notation keys: {"user.name":"John","user.address.city":"NYC"}. This is useful for CSV export, database inserts, and searching for values by key path.

How are arrays handled?

Array elements are flattened with bracket notation: "items[0].name", "items[1].name", etc. This preserves the index and structure of your arrays.

Can I flatten in both directions?

Yes. The Unflatten button takes a flat object with dot-notation keys and restores the original nested structure. This is useful when you get data in flat format (like from a CSV or a key-value store) and need to reconstruct the original JSON.

When to Flatten JSON

Flattening JSON is a practical technique when you need to bridge between nested data structures and flat storage systems. If you're inserting API data into a SQL database, a flat list of column→value pairs is much easier to work with than nested objects.

It's also handy for debugging — searching for "user.address.city" in a flat map is straightforward, while finding the same value in a 5-level deep nested object requires manually expanding each level. Some logging and monitoring systems (like Elasticsearch) use dot-notation keys internally for this reason.

The reverse (unflattening) is useful when you're loading data from a CSV or a key-value database back into an application that expects nested JSON. For example, environment variables like DB_HOST and DB_PORT can be unflattened into {"db": {"host": "...", "port": "..."}}.

Related Articles