Flatten & Unflatten
JSON online, free & instant
Convert deeply nested JSON into flat dot-notation keys or restore flat keys back to nested structure. Works entirely in your browser — no upload, no account, no waiting.
Open Flatten / Unflatten ToolFlatten deep nesting into a single level
No account. No upload. No nonsense.
100% Private
Your JSON never leaves your device. There is no server receiving your data.
Instant Output
Conversion happens as you type. No round-trips to a backend, no latency.
Lossless Round-Trip
Flatten then unflatten — you get back the exact original structure, arrays and all.
Related JSON tools
Common questions answered
What does flattening JSON mean?
Flattening converts a deeply nested JSON object into a single-level object where each key is a dot-separated path. For example, {"user":{"name":"Alice"}} becomes {"user.name":"Alice"}. This is useful for CSV export, logging, search indexing, and database storage.
Is the JSON flatten/unflatten tool free?
Yes, completely free with no account or signup required.
How are arrays handled when flattening?
Array elements are indexed with dot notation like "items.0", "items.1", etc. This preserves the order and structure so you can unflatten back to the original array.
Can I unflatten back to the original nested structure?
Yes. The tool supports both flatten and unflatten. A flattened object with dot-notation keys can be restored to its original nested structure with a single click — the round-trip is lossless.
Is my data sent to a server?
No. All conversion runs entirely in your browser using JavaScript. Your JSON is never uploaded or transmitted.
What is JSON flattening?
JSON flattening transforms a nested object into a single-level object where every value is accessible through a dot-notation key path. For example, {"user": {"name": "Alice"}} becomes {"user.name": "Alice"}. Flattened JSON is useful for importing data into spreadsheets, flat-schema databases, or analytics tools that do not support nested structures.
This tool handles all JSON types during flattening: nested objects become dot-separated paths, arrays use bracket notation (items[0], items[1]), and primitive values remain as leaf values. You can also unflatten — converting dot-notation keys back into nested structures. This round-trip capability makes it useful for transforming data between systems with different requirements.
{
"user": {
"name": "Alice",
"address": {
"city": "Portland"
}
},
"tags": ["a", "b"]
}
{
"user.name": "Alice",
"user.address.city": "Portland",
"tags[0]": "a",
"tags[1]": "b"
}
Get the most out of this tool
- Flatten JSON before importing into spreadsheets — each dot-notation key becomes a column header.
- Use bracket notation for arrays: "users[0].name" is more readable than "users.0.name" in flattened output.
- Flatten deeply nested API responses to quickly see all available fields without expanding the tree manually.
JSON flattening in depth
JSON flattening converts a nested JSON object into a single-level object where nested keys are represented as dot-separated paths. For example, {"address": {"city": "Portland"}} becomes {"address.city": "Portland"}. This transformation is useful when working with systems that do not understand nested JSON — many spreadsheet tools, SQL databases, and analytics platforms work only with flat key-value structures.
The flattening algorithm performs a depth-first traversal of the JSON tree. For each leaf value (a string, number, boolean, or null), it constructs the full path from root to leaf by joining all parent keys with a separator (usually a dot). For arrays, the index is included in the path: {"items": ["a", "b"]} becomes {"items.0": "a", "items.1": "b"}. This preserves all values in a lossless way — the original structure can be reconstructed from the flat form.
The separator character matters for usability. Dot notation (field.subfield) is the most common convention and is what JSONPath expressions use. Bracket notation (field[subfield]) mimics JavaScript property access. For CSV column headers, underscore separation (field_subfield) avoids the dot character that some tools treat specially. This tool uses dot notation by default but can be adjusted for compatibility with different target formats.
Elasticsearch, the popular search and analytics engine, uses dot notation extensively. When you index a document with nested fields in Elasticsearch, it internally flattens them. Defining explicit mapping for nested fields versus using Elasticsearch's flattened field type is a common architectural decision — using this tool to preview the flattened form helps you understand what Elasticsearch will store internally.
The reverse operation — unflattening — reconstructs the nested structure from the flat key-value form. This is useful when you have CSV or tabular data with dot-separated column headers that you want to convert back to nested JSON. The unflatten operation splits each key on the separator, creates the nested path of objects, and assigns the value at the leaf. This tool supports both flatten and unflatten operations.
Environment variables are inherently flat — environment variable names cannot contain dots or brackets in most shells. When application configuration is stored as nested JSON but needs to be exported as environment variables, flattening with underscore separation and uppercase conversion produces the standard format: {"db": {"host": "localhost"}} becomes DB_HOST=localhost. This pattern is used by many twelve-factor app configurations.
When developers use this tool
Additional frequently asked questions
Is JSON flattening lossless? Can I always reconstruct the original?
Yes, for standard JSON. Every value is preserved at its full path. The unflatten operation splits keys on the separator and reconstructs the nested hierarchy. The only edge case is when original keys contain the separator character (e.g., a key named "a.b") — the flattened form is ambiguous in that case. Use a separator that does not appear in your key names.
What happens to arrays when flattening?
Array elements are indexed in the flattened output: items.0, items.1, items.2. This preserves the order and all values. When unflattening, numeric keys at any path level are interpreted as array indices, reconstructing the original array structure. Mixed arrays with both objects and primitives are handled by including the index for all elements.
Can I choose a different separator than a dot?
Yes. Common alternatives include underscores (safe for environment variables and database column names), double underscores (for namespaced environment variables), slashes (for file-system-like path notation), and brackets (for JavaScript-style property access). Choose a separator that does not conflict with the characters already used in your JSON key names.
How does flattening handle null values?
Null values are preserved as null in the flattened output at their full key path. This is important — null is semantically different from a missing key. When unflattening, null values are correctly placed at the path they occupied in the flattened form, preserving the distinction between null and absent.