Turning dotted keys back into nested JSON
Flat keys show up in many places: a spreadsheet export with columns named address.city, a translation file with keys like checkout.button.label, a key-value store, form field names such as users[0].email, or a config that was flattened to be diffed. A program usually needs the nested form instead, the one where address is an object with a city inside it. Unflattening rebuilds that structure by reading each key as a path and placing its value at the end of it.
Each key is split on the separator you pick. With the dot, user.address.city becomes three levels: user, then address, then city. Bracket positions are always read too, so tags[0] and tags.0 mean the same thing, and the two styles can be mixed in one key, as in users[0].name. Keys that share a beginning share a parent, so user.name and user.email end up side by side in one user object, in the order their keys first appeared.
Numbered keys become lists, but only when that loses nothing. If the keys under a parent are exactly 0, 1, 2 and so on, starting at zero with no gaps, they become a JSON list. If they start at 1, skip a number, or are mixed with other names, they stay object keys called "1", "3" and so on, because forcing them into a list would shift values or leave holes. You can also switch list building off and keep every numbered key as an object key, which is what you want for data such as a map from HTTP status codes to messages.
Some inputs cannot be unflattened without losing data, and the tool refuses them rather than guessing. If one key sets a to the number 1 and another sets a.b, a would have to be both a number and an object. The error names both keys, so you can see which one is wrong. An empty object or list in the input, written as {} or [], is treated as an empty container that later keys may fill.
The JSON is read with a parser that keeps numbers as the digits you wrote, so long IDs and precise decimals come through unchanged, and the output is indented with two spaces. It is the reverse of JSON Flatten: flatten, edit the flat keys in a spreadsheet or text editor, then unflatten with the same separator to get the nested file back. Everything runs in your browser and nothing is uploaded.