Rebuilding a tree from path strings
Unflattening reads each dotted key as a route and creates the containers along the way. Given `user.address.city`, it makes a `user` object, an `address` object inside it, and finally sets `city` to the leaf value. Process every key in the flat map this way and the original nested structure reassembles itself.
The decision the algorithm makes at each step is whether to create an object or an array, and it uses the notation to decide. A bracketed numeric segment like `items[0]` means the parent must be an array; a plain segment like `items.first` means it must be an object. This is why the bracket convention matters rather than being cosmetic - it is the only signal available about what kind of container to build.