How to Flatten JSON: Dot Notation, Arrays & Unflattening
Learn how to flatten JSON the right way - choose dot, bracket, slash, or underscore delimiters, handle array indexes, and unflatten flat JSON back to nested data.
Nested JSON is great for APIs, but flat keys are easier for spreadsheets, databases, logs, search indexes, and comparison tools. To flatten JSON means turning a nested structure into a one-level object where each key describes the path to a value. This guide shows how to flatten JSON online, pick a delimiter, handle arrays, and unflatten the result when you need the nested shape back.
The quickest way: flatten JSON online
Paste nested JSON into the JSON Flatten tool, choose a delimiter, decide whether arrays should use indexes, and press Flatten JSON. The output is a flat JSON object you can copy or download.
Use a client-side JSON flattener when working with private API responses, customer exports, config files, or logs. The conversion runs in your browser, so nothing is uploaded.
Use it when: you need flat keys for CSV, tables, analytics, comparisons, search, or storage.
What flattened JSON looks like
Nested JSON:
{
"user": {
"id": 7,
"address": { "city": "London" }
}
}
Flattened with dot notation:
{
"user.id": 7,
"user.address.city": "London"
}
The values stay the same. Only the keys change.
Choose a delimiter
There is no single universal flat-key style. Common options are:
- Dot notation -
user.address.city - Bracket notation -
user[address][city] - Slash paths -
user/address/city - Underscore keys -
user_address_city
Dot notation is common in JavaScript and data tools. Bracket notation is useful when a downstream system already expects PHP-style paths. Slash paths are easy to scan in logs. Underscore keys are useful for databases and spreadsheets that dislike punctuation.
Handle arrays with indexes
Arrays need a deliberate choice. With array indexes enabled:
{ "roles": ["admin", "editor"] }
becomes:
{
"roles.0": "admin",
"roles.1": "editor"
}
That is best when every item needs its own path. If you want to preserve arrays as values, turn array indexing off.
Unflatten JSON back to nested data
Flattening should be reversible when paths are unambiguous. A flat object like:
{
"user.name": "Ada",
"roles.0": "admin"
}
can become:
{
"user": { "name": "Ada" },
"roles": ["admin"]
}
The online tool includes an unflatten JSON mode with delimiter auto-detection for dot, bracket, slash, and underscore keys.
Flatten JSON in JavaScript
A simple recursive flattener looks like this:
function flatten(value, prefix = "", out = {}) {
if (Array.isArray(value)) {
value.forEach((item, index) => flatten(item, `${prefix}.${index}`, out));
} else if (value && typeof value === "object") {
for (const [key, child] of Object.entries(value)) {
flatten(child, prefix ? `${prefix}.${key}` : key, out);
}
} else {
out[prefix] = value;
}
return out;
}
Production tools add delimiter options, array controls, and unflatten support.
Which method should you use?
For one-off conversion, use the online JSON Flatten tool: paste JSON, choose delimiter and array handling, then copy the flat output. Use JavaScript when flattening is part of an app or data pipeline. Either way, choose the delimiter your downstream tool expects, and be intentional with arrays.
Need tabular output too? Try JSON to CSV, JSON to Table, or JSON to Excel.
Ready to merge your JSON?
Combine files or snippets in your browser — free and private.
Open the merge toolKeep reading