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.
Enjoying WizTools123? Help keep our server infrastructure 100% free and open for everyone.
How to Flatten JSON
A few steps, and nothing is uploaded.
What to Know About Flattening
Separators, empty branches, and the one place a round trip can go wrong.
{} 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.
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.
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.
Key Features & Capabilities
What this tool does, and what it deliberately does not.
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.
Every Other JSON Tool
10 more tools in this set. All free, all in your browser.