JSON Flattener
Flatten nested JSON to dot-notation keys or unflatten dot-notation back to nested
Shortcuts: Ctrl+Enter run · Ctrl+L clear · Ctrl+D download
About JSON Flattener
JSON Flattener converts a deeply nested JSON object into a single-level object using dot notation keys (e.g., `user.address.city`). It also works in reverse — unflattening a dot-notation object back to its nested form. Flattening is useful for storing nested data in flat stores like spreadsheets, SQL columns, or environment variable files.
- ✓Flattens any depth of nesting into single-level dot-notation keys
- ✓Unflattens dot-notation keys back to the original nested structure
- ✓Handles arrays by using numeric indices in the path (e.g., `items.0.name`)
- ✓Configurable delimiter — use dot, slash, or any custom separator
Flattening JSON for Spreadsheets, Databases, and Diffs
Nested JSON is great for representing relationships, but a lot of tools that developers rely on every day — spreadsheets, SQL tables, environment variable files, CSV exports — only understand flat key-value pairs. Flattening bridges that gap by collapsing a nested structure into a single level, encoding the original hierarchy directly into the key names.
How flattening works
// Nested
{
"user": {
"name": "Alice",
"address": { "city": "Austin", "zip": "78701" },
"tags": ["admin", "beta"]
}
}
// Flattened (dot delimiter)
{
"user.name": "Alice",
"user.address.city": "Austin",
"user.address.zip": "78701",
"user.tags.0": "admin",
"user.tags.1": "beta"
}Every nested object key becomes part of the path, joined by the delimiter. Arrays are handled the same way, using the numeric index as the path segment — so "user.tags.0" means "the first element of the tags array inside user".
Why flatten JSON
- ·CSV and spreadsheet export — spreadsheet columns are flat by nature, so flattening turns each unique path into its own column
- ·SQL columns — storing nested objects in a relational table often means either a JSON column (which can't be indexed easily) or flattened columns that map directly to fields
- ·Environment variables — config systems like dotenv or container environment variables are flat key=value pairs; flattening a config object gives you ready-to-use variable names
- ·Easier diffing — a change deep inside a nested object becomes a single changed line in flat form, rather than shifting the surrounding structure
Choosing a delimiter
The dot (`.`) is the default and works well for most data. But if your original keys already contain dots (e.g. a key literally named "user.name"), flattening with a dot delimiter creates ambiguity — you can't tell whether "user.name" in the flattened output came from nesting or was already a single key. In that case, pick a delimiter that doesn't appear in any of your keys, such as a slash (`/`) or a double underscore (`__`), which is a common convention for environment variables.
Tip: If you're flattening data to load into a spreadsheet, run a quick check first: does any record have a much deeper structure than the others? A single deeply-nested record will generate columns that are empty for every other row, which can make the spreadsheet unwieldy. Consider flattening only the top one or two levels for that kind of data.
Unflattening — going back to nested form
Unflattening reverses the process: it reads each dot-delimited key, splits it into segments, and rebuilds the nested object structure, creating arrays automatically when it encounters consecutive numeric segments (like ".0", ".1"). This is useful after editing flattened data in a spreadsheet — export the edited CSV back to JSON, then unflatten it to restore the original nested shape your application expects.