I have this JSON string:
{
"name": ".",
"_type": "folder",
"children": [
{
"name": "Beverages",
"_type": "folder",
"children": [
{
"name": "Water",
"_type": "file"
},
{
"name": "Tea",
"_type": "folder",
"children": [
{
"name": "White tea",
"_type": "file"
},
{
"name": "Green tea",
"_type": "folder",
"children": [
{
"name": "Sencha",
"_type": "file"
},
{
"name": "Pi Lo Chun",
"_type": "file"
},
{
"name": "Matcha",
"_type": "file"
},
{
"name": "Gyokuro",
"_type": "file"
}
]
},
{
"name": "Black tea",
"_type": "file"
}
]
},
{
"name": "Coffee",
"_type": "file"
}
]
}
]
}
It represents this folder:
│
└───Beverages
│ Coffee
│ Water
│
└───Tea
│ Black tea
│ White tea
│
└───Green tea
Gyokuro
Matcha
Pi Lo Chun
Sencha
The problem is that the JSON is ordered by the anti-lexicographical order: you can see Water-Tea-Coffee
under Beverages
. That is, it rather represents this structure:
.
|
`- Beverages
|
+- Water
|
+- Tea
| |
| +- White tea
| |
| +- Green tea
| | |
| | +- Sencha
| | |
| | +- Pi Lo Chun
| | |
| | +- Matcha
| | |
| | `- Gyokuro
| |
| `- Black tea
|
`- Coffee
But Tea
is a folder, while Water
and Coffee
are files (they don't have children). I'd like to have the folders following by the files, as in the first tree picture.