Skip to main content
WizTools123
WizTools123
Free Online Tools

Tool Categories


JSON Tools New Tool

Free Online JSON Flattener and Unflattener

Flatten nested JSON into a single level of key and value pairs, written either as a.b[0].c or as a_b_0_c, and build the nesting back again from flat keys. Empty objects and arrays are kept so a round trip returns the same document. Output as JSON, as key and value lines, as CSV or as environment variables.

Free Forever Nothing Uploaded Both directions Many files at once
Free Online JSON Flattener and Unflattener
Share this tool
Advertisement Slot (Top Banner) Google AdSense Unit • Responsive Banner
JSON Flattener and Unflattener Your file is read inside this tab. Nothing is uploaded anywhere.
Drop the JSON files you want flattened Or paste one below. Flat keys are recognised and rebuilt instead. Choose files Up to 15 MB per file. Nothing is uploaded.
0%
Or paste it
Reading
Which way
Key style
Details
Write it as
Writing

- direction 0 pairs 0 levels deep 0 longest key

Result
0 characters 0 lines 0 B
Buy Us A Coffee

Enjoying WizTools123? Help keep our server infrastructure 100% free and open for everyone.

Buy Us A Coffee
Sponsored Content (Below Tool) Google AdSense Placement

How to Flatten JSON

A few steps, and nothing is uploaded.

1
Paste the JSON, or drop the files Nested or already flat. The sample has a nested array, an empty object, an empty array and two awkward keys.
2
Leave the direction on automatic A document with nesting gets flattened; a document that is already one level of dotted keys gets rebuilt. What it decided is shown next to the box.
3
Pick the key style Dots and brackets read well and survive a round trip. Underscores are what form fields and environment variables need.
4
Take the result away JSON, key and value lines, CSV for a spreadsheet, or environment variables. Several files download as one zip.

What to Know About Flattening

Separators, empty branches, and the one place a round trip can go wrong.

Empty objects and arrays are kept on purpose. There is nothing inside {} or [] to make a pair out of, so a plain flattener drops them, and rebuilding gives you a document that is missing them. That is a real difference: a field that exists and is empty is not the same as a field that is absent. They are written as a pair holding an empty value, and the switch lets you drop them if you would rather.
Dots and brackets survive a round trip. Underscores cannot always. In a[0].b the bracket says the zero is an array index. In a_0_b there is nothing to say whether that zero is an index or a key literally called "0". The switch decides, and it is on by default because an index is far more common, but if your data really has numeric keys turn it off.
A key with a space or a dot in it gets brackets and quotes. Joined with a dot, a key called run.id becomes meta.run.id, which reads as two levels, and rebuilding it gives you an object that was never there. Written as meta["run.id"] there is no ambiguity and the round trip is exact. It is noisier, so there is a switch, and turning it off is the right choice when the keys are headed for a spreadsheet rather than back into JSON.
Flat keys are what forms, spreadsheets and environment variables all speak. An HTML form cannot post a nested object, a spreadsheet column cannot hold one, and an environment variable is a single string. Flattening is how nested configuration gets into all three, and unflattening is how it comes back.
The environment variable shape only takes simple values. A variable holds one string, so objects and arrays have no sensible form. Keys become upper case with underscores, and anything that is not a plain value is left out, with the count telling you how many.
Arrays keep their order, always. Flattening numbers the items and rebuilding reads those numbers back, so item three stays item three. Gaps are the exception: if a key is missing from the middle of a run the gap is filled with null rather than silently shifting everything up.

Key Features & Capabilities

What this tool does, and what it deliberately does not.

Both directions Flatten and rebuild on one page, because whoever does one usually does the other soon after.
Works out the direction A nested document gets flattened, a flat one gets rebuilt, and it tells you which it chose.
Three key styles Dots and brackets, plain underscores, or any separator you like for an awkward target.
Four output shapes JSON, key and value lines, CSV for a spreadsheet, or upper case environment variables.
Many files at once Drop a folder of files, set the options once, and download every result in a single zip.
Nothing is uploaded Everything is parsed in this tab, so configuration files with secrets in them stay put.

About Flattening JSON

Flattening JSON is one of those jobs that sounds like a one line function and then is not. Nested data has to become flat whenever it meets something that cannot nest: an HTML form, a spreadsheet column, a set of environment variables, a database table of settings, a translation file. In the other direction, the same data has to come back out of those places into the shape the program expects. So the two halves are really one job, done twice.

The part that catches people out is the empty branch. An object with nothing in it, or an array with nothing in it, produces no key and value pair at all, because there is no value to pair with anything. A flattener that simply ignores them loses them, and the document you rebuild is quietly different from the one you started with. Whether that matters depends on what reads it, which is exactly why it should be your decision rather than a side effect, so empty branches are kept by default and there is a switch to drop them.

The other part is telling an array index from a key that happens to be a number. Dot and bracket notation has no problem here, because the bracket is the whole point of the bracket. Plain underscore keys have no way to express the difference, so rebuilding has to guess, and a guess that is wrong turns an object into an array or the reverse. The honest answer is a switch and a table showing you the pairs, rather than a silent assumption.

Frequently Asked Questions

Styles, arrays, round trips and awkward keys.

Dots and brackets if the keys are for people to read or for a round trip, because the brackets make array indexes unambiguous. Underscores if the keys are going into form fields, environment variables or anywhere a dot is not allowed.

In dot style, yes, with both switches left on: awkward keys are quoted so they are read back as one key, and empty objects and arrays are kept so they survive. Underscore style cannot be exact, because nothing in it distinguishes an array index from a numeric key.

Each item gets its index as a key, so order is preserved both ways. In dot style the index is in brackets. When rebuilding, whole number keys are treated as array positions unless you turn that switch off.

In dot style it is written in brackets and quotes, as meta["first name"], so that rebuilding reads it as one key rather than two levels. Switch that off and it is written plainly, which is tidier for a spreadsheet but no longer an exact round trip.

Because an environment variable holds a single string, so there is no sensible way to write an object or an array into one. Those pairs are left out and the count tells you how many were skipped.

Yes. Drop in as many files as you like, set the options once, and download every result as a single zip. Each file is handled on its own, so one broken file does not stop the rest.

Every Other JSON Tool

10 more tools in this set. All free, all in your browser.

Advertisement Slot (Bottom Banner) Google AdSense Unit • Responsive Banner