JSON Flatten / Unflatten

Flattens nested JSON into single-level key paths like users.0.name, or rebuilds the nesting from them, with a delimiter you choose. Empty objects and arrays survive; all processed locally.

Last updated:

Paste nested JSON here...
Loading editor...
Loading editor...

JSON Flatten & Unflatten — Convert Nested JSON to Flat Key Paths

What JSON Flatten does

Flatten turns nested objects into delimiter-separated paths. Unflatten reconstructs nested data from a path map. Choose a delimiter that is absent from your original field names and compare the reconstructed structure before relying on a round trip.

Worked examples

Flatten an array of customer records

A report needs flat keys from a nested response. Select Flatten and leave the delimiter as a period.

Input

{"users":[{"name":"Ada"},{"name":"Lin"}],"meta":{}}

Output

{
  "users.0.name": "Ada",
  "users.1.name": "Lin",
  "meta": {}
}

Array positions become numeric path segments. The empty meta object remains a value because it has no children to expand.

Restore nested fields from flat paths

A flat map uses a custom separator because some keys already contain periods. Select Unflatten and enter ::.

Input

{"build::platform":"linux","build::version":"1.2"}

Output

{
  "build": {
    "platform": "linux",
    "version": "1.2"
  }
}

Only the chosen separator splits the path. Both fields are grouped under build, and the version string stays intact.

What to check before using the output

A delimiter can appear in an original key

A literal key a.b and a nested b inside a can both produce the path a.b. Use a separator absent from your field names or choose a representation that escapes each path segment.

The root must be an object

Arrays can appear inside an object and become numeric path segments. A top-level array is rejected, so wrap it in an object if you need to flatten its entries.

Large inputs use Run

Over 1 MB, the editor holds the pasted document until you press Run. A worker handles the transform, and the full result remains available through Download even when the editor only displays a preview.

How to Use the Tool

  1. Select the operation: "Flatten" (nested → flat) or "Unflatten" (flat dot-keys → nested).
  2. Paste your JSON into the input editor.
  3. Choose the separator character: dot (.) is the default, but slash (/) and underscore (_) are also available.
  4. Click "Convert" — the output shows all values at a single depth level with composite key paths.
  5. Copy the flattened JSON for use in ETL pipelines, Elasticsearch mappings, or environment variable configs.

Key Features & Specifications

  • Bidirectional: flatten nested objects to dot-path keys and unflatten them back
  • Configurable separator: dot (.), slash (/), or custom character
  • Correctly handles nested arrays with numeric indices (users.0.name)
  • Preserves all value types (strings, numbers, booleans, null) at leaf nodes
  • Useful for ETL pipelines, Elasticsearch ingestion, config systems, and JSON diff preparation

Frequently Asked Questions (FAQ)

Q:How are arrays handled during flattening?
Array elements are indexed numerically: an array at "items" with three elements produces keys "items.0", "items.1", and "items.2". During unflattening, numeric keys are recognized and reconstructed into arrays. You can configure if arrays should be left untouched or flattened.
Q:What if my object keys contain dots?
If your original key names contain the separator character (e.g., a key literally named "first.name"), flattening becomes ambiguous. The tool escapes such keys using bracket notation (first\.name). Choose a separator character not used in any key names to avoid this issue.
Q:Can I use flattened JSON directly in MongoDB queries?
Yes! MongoDB natively understands dot notation for querying nested documents. A flattened key like "address.city" maps directly to MongoDB's $match: {"address.city": "London"} query syntax.
Q:Does flattening preserve the original data types?
Yes. Leaf node types—strings, numbers, booleans, and null values—are preserved exactly. Only the structural layers (enclosing objects and arrays) are dismantled and converted into flattened path names.