{
"color": "red",
"count": 2
}Spreadsheets and some query tools want one row of keys, not a tree. Flatten walks a JSON value and writes a single object whose keys are paths. A nested object uses dots. An array uses bracket indexes. A key that itself contains a dot or a bracket is quoted so the path can be read back.
{"user":{"name":"Ada","city":"Pune"}} flattens to user.name Ada and user.city Pune. Unflatten of that object returns the original nesting. A path that would collide, such as a key a set to 3 and a key a.b set to 4, is rejected on the way back rather than silently overwritten.
Empty objects and empty arrays are preserved in the path scheme the unflatten step understands. The result is still JSON. It is not CSV. JSON to CSV is the page that turns an array of objects into rows, and it flattens nested fields into dotted column names on its own.
{"user":{"name":"Ada","city":"Pune"}}
{ "user.name": "Ada", "user.city": "Pune" }. Unflatten returns the nested user object.
Dot paths and bracket indexes name every leaf, which is the shape a column list and the unflatten step both understand.
Keys that contain dots are quoted in the path so unflatten can tell them from nesting.
No. You get one JSON object of path keys. JSON to CSV expects an array of records.
Unflatten rejects a conflict, such as a being both a number and an object.
Yes. The first element is [0] in the path.
The walk follows the document order. Sort keys if you need alphabetical paths.