Convert deeply nested JSON into flat key-value pairs using dot notation. Instantly flatten or unflatten any JSON object online — free, no signup required.
JSON flattening is the process of taking a deeply nested JSON structure and transforming it into a single-level object where every value is directly accessible by a single composite key. The key encodes the full path to the value through the original hierarchy.
Consider this nested JSON:
{
"user": {
"name": "Alice",
"address": {
"city": "London",
"zip": "EC1A"
}
}
}
After flattening, the result is:
{
"user.name": "Alice",
"user.address.city": "London",
"user.address.zip": "EC1A"
}
The structure is completely preserved — just expressed differently. Every piece of information is still there; it is simply reorganized into a flat dictionary where the dot-separated key tells you exactly where that value originally lived in the hierarchy.
Dot notation is the standard naming convention for flattened keys. Each level of nesting in the original JSON is separated by a period character. This convention is borrowed from how most programming languages access nested object properties.
a.b.c means the value at obj.a.b.c in the nested versionitems.0.nameitems[0].nameOur JSON Flatten Tool uses dot notation by default, which is the most widely supported format across libraries, databases, and query languages. If your target system requires a different separator (such as double underscore __ or forward slash /), you can configure the separator in the tool settings.
Dot notation is used natively in:
glom and jmespath librarieslodash.get / lodash.set functionsThere are several practical scenarios where flattening JSON is not just convenient but necessary:
Elasticsearch's default mapping handles nested objects, but there are cases where you need to index documents with explicit flat field paths — particularly when you want to avoid the overhead of the nested type and instead store a flattened representation. The flattened field type in Elasticsearch directly accepts pre-flattened JSON objects.
CSV files are inherently two-dimensional — columns and rows. They cannot represent nested structures. When you need to export JSON data into a spreadsheet or CSV file, flattening is the essential first step. Each dot-notation key becomes a column header, and each value fills the corresponding cell.
HTML forms submit data as flat key-value pairs. Many server-side frameworks (like PHP, Laravel, and Rails) support dot or bracket notation in form field names to reconstruct nested objects server-side. Flattening your JSON to understand what form field names to use is a common debugging task for developers building dynamic forms.
Diffing two nested JSON objects visually is difficult. Flattening both objects first and then comparing them side-by-side as flat dictionaries makes it easy to spot exactly which keys changed, were added, or were removed — without having to mentally traverse nested structures.
Tools like Helm (Kubernetes), Terraform, and various CI/CD systems accept flat key-value overrides using dot-notation paths. When you want to override a single deeply nested value in a large configuration, knowing its flattened key path is essential.
Unflattening is the reverse operation: taking a flat dictionary of dot-notation keys and reconstructing the original nested JSON structure. This is equally important in practice.
Common use cases for unflattening include:
__ or . as separatorsOur tool handles both directions. Paste a flat object and click Unflatten to get back the nested representation. The round-trip is lossless as long as your keys were created by flattening in the first place.
Flattening a JSON object means converting its nested hierarchy into a single level of key-value pairs. Nested keys are combined using a separator — typically a dot — so every value is addressable by a single composite key string. For example, {"a":{"b":1}} becomes {"a.b":1}.
Yes. Array elements are included in flattened output using their numeric index as part of the key path. For example, {"tags":["json","api"]} flattens to {"tags.0":"json","tags.1":"api"}. Some implementations use bracket notation instead of dot notation for array indices.
Flatten JSON when you need to work with systems that expect flat key-value pairs: Elasticsearch flat field types, CSV export, spreadsheet imports, environment variable configuration, or HTML form field names. It is also useful for diffing two JSON documents by comparing their flat representations line by line.
Yes. Unflattening reconstructs the original nested structure from dot-notation keys. Our tool supports both directions. Simply paste your flat JSON and select Unflatten to restore the original hierarchy. The operation is lossless as long as the flat keys were originally produced by a consistent flatten operation.
Free, instant, 100% private. No account needed.
Flattening JSON converts deeply nested objects into a single-level key-value map where nested paths become compound keys. This is essential for loading JSON into SQL tables, Elasticsearch, or spreadsheets.
// Nested (3 levels deep)
{
"user": {
"name": "Alice",
"address": {
"city": "London",
"zip": "EC1A 1BB"
}
}
}
// Flattened (dot notation)
{
"user.name": "Alice",
"user.address.city": "London",
"user.address.zip": "EC1A 1BB"
}
// JavaScript
function flatten(obj, prefix = "") {
return Object.keys(obj).reduce((acc, key) => {
const path = prefix ? `${prefix}.${key}` : key;
if (typeof obj[key] === "object" && !Array.isArray(obj[key])) {
Object.assign(acc, flatten(obj[key], path));
} else {
acc[path] = obj[key];
}
return acc;
}, {});
}
// Python (using pandas)
import pandas as pd
pd.json_normalize(nested_data)
| Delimiter | Example | Best For |
|---|---|---|
| Dot (.) | user.address.city | Most common, readable |
| Underscore (_) | user_address_city | SQL-friendly column names |
| Double underscore (__) | user__address__city | Avoids conflicts with _ in names |
| Slash (/) | user/address/city | JSON Pointer compatible |
Flattening JSON means taking a deeply nested JSON object — one where values are nested inside objects inside objects — and transforming it into a single-level object where every value is directly accessible by a single composite key. The composite key encodes the entire path through the original hierarchy, with each level separated by a delimiter (usually a dot or underscore).
A flat JSON object has no nesting: every key maps directly to a primitive value (string, number, boolean, or null). There are no nested objects and no arrays — just key-value pairs at one level.
// Before: Nested JSON (3 levels deep)
{
"user": {
"id": 42,
"name": "Alice Johnson",
"address": {
"street": "123 Main St",
"city": "Portland",
"state": "OR",
"zip": "97201"
},
"preferences": {
"theme": "dark",
"notifications": true
}
},
"account": {
"plan": "pro",
"seats": 5
}
}
// After: Flat JSON (dot notation, all values at one level)
{
"user.id": 42,
"user.name": "Alice Johnson",
"user.address.street": "123 Main St",
"user.address.city": "Portland",
"user.address.state": "OR",
"user.address.zip": "97201",
"user.preferences.theme": "dark",
"user.preferences.notifications": true,
"account.plan": "pro",
"account.seats": 5
}
No information is lost during flattening — the complete structure is preserved in the key names. You can always reconstruct the original nested JSON from the flat version by splitting the keys on the delimiter and rebuilding the object tree. This reverse operation is called unflattening.
Flattening is not always the right choice — it depends on what you need to do with the data. Here are the most common situations where using a JSON flattener online is the right tool:
Relational databases store data in flat tables with typed columns. To insert a nested JSON object into a SQL table, you must first flatten it so that each key maps to a column name. The flat keys like user_address_city become column headers.
CSV files are inherently flat: every row has the same set of column names. Nested JSON objects cannot be directly exported to CSV. Flattening the JSON first converts the hierarchy into column headers, making a direct CSV export possible. Our JSON to CSV converter can handle this automatically.
Elasticsearch's flattened field type maps a whole object to a single flat field and is suitable for deeply nested or dynamic objects. Pre-flattening your data before indexing can simplify mappings and improve query performance for dynamic schemas.
Diffing nested JSON visually is difficult. Flattening both objects to single-level dictionaries first and comparing them line-by-line makes it trivial to identify exactly which keys changed, were added, or were removed — without navigating a deep tree. Try our JSON diff tool for a visual comparison.
Tools like Helm (Kubernetes), Terraform, and many CI/CD systems accept flat key-value overrides using dot-notation paths. Knowing a value's flattened key path is required to override just that one nested value without rewriting the entire config object. The JSON to .env converter uses a similar flattening approach.
Both operations are equally important and this flatten JSON online tool supports both directions. Here is a detailed comparison:
| Aspect | Flatten JSON | Unflatten JSON |
|---|---|---|
| What it does | Converts nested JSON into a single-level key-value map | Reconstructs original nested JSON from flat dot-notation keys |
| Input | Nested JSON with any depth | Flat JSON with dot-notation or underscore keys |
| Output | Flat JSON: {"a.b.c": "value"} | Nested JSON: {"a": {"b": {"c": "value"}}} |
| Data loss | None — all data preserved in key names | None — lossless if original was produced by flattening |
| Common use cases | CSV export, SQL insert, Elasticsearch indexing, JSON diff | Rebuild from form data, env vars, Redis/DynamoDB flat stores |
| Default delimiter | Dot (.) or underscore (_) | Must match the delimiter used during flattening |
| Array handling | Array indices become part of the key: items.0.name | Numeric keys are reconstructed back into arrays |
| Round-trip | Flatten then unflatten restores exact original structure | Unflatten then flatten reproduces the same flat keys |
| Python equivalent | pd.json_normalize(obj) | Manual reconstruction or glom library |
Also useful: JWT Decoder | JSON Key Sorter | Base64 JSON Tool | What is JSON? | JSON vs YAML