{
"color": "red",
"count": 2
}Unflatten JSON reads an object whose keys are paths and builds the nesting those paths describe. Dots open objects. Bracketed numbers open arrays. item.name and item.qty become an item object. tags[0] and tags[1] become a tags array. The result is pretty-printed.
A flat object whose keys contain neither dots nor brackets is already the structure, so {"color":"red","count":2} comes back unchanged. Conflicting paths are refused: a key that is both a leaf and a parent, a mix of array and object at the same step, or a duplicate path. An empty-string key is the root itself, and it is allowed only when it is the only key.
For a rebuild, paste {"item.name":"Pen","item.qty":4,"tags[0]":"red","tags[1]":"blue"}. The sample {"color":"red","count":2} has no dots.
The path object returns item with name Pen and qty 4, plus tags as ["red", "blue"]. The sample returns { "color": "red", "count": 2 }.
The paths flatten produced are enough to rebuild the objects and arrays, so the flat form is a real encoding and not a one-way loss.
Those keys are single segments. Unflatten nests only keys that contain a dot or a bracket index.
As a bracket index on the path: tags[0], tags[1]. The indexes become array positions.
The same path written twice, a value sitting where a child path still needs an object, or an array index and an object key mixed at one step. The message names the path.
A single key of "" holds the root value. Any other key beside it is a conflict.
The paste has to be an object of path keys. An array is refused with Expected an object with path keys.