-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question about making json object from file directory #1449
Comments
This comment has been minimized.
This comment has been minimized.
Is the |
@nlohmann - thanks for the quick reply! That struct isn't mandatory at all. I wasn't sure how to approach it. |
This seems so closed to a json j;
std::string p = "/Folder 1/0/Folder 2/0/Folder 3/0/Folder 4/0";
j[json::json_pointer(p)] = "fileInFolder"; This produces {
"Folder 1": [
{
"Folder 2": [
{
"Folder 3": [
{
"Folder 4": [
"fileInFolder"
]
}
]
}
]
}
]
} If this is what you want, then it should be easy to generate the string from the vector. |
(See https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a8ab61397c10f18b305520da7073b2b45.html#a8ab61397c10f18b305520da7073b2b45 for some information on the interface) |
@nlohmann - that is super helpful. Thanks for the info and speedy reply. for anyone finding this - also helpful to add the initial file as array so you can push_back to it like so:
|
I'm attempting to scan a folder and its subfolders to make a json object of the entire directory. So far I have this:
which works somewhat - it returns this:
{ "Folder 1": [ { "Folder 2": [ { "Folder 3": [ { "Folder 4": [ { "fileInFolder": [] } ] } ] } ] } ] }
and i'd like to have the last item as a string in the array - not another object - like so:
{ "Folder 1": [ { "Folder 2": [ { "Folder 3": [ { "Folder 4": [ "fileInFolder" ] } ] } ] } ] }
More importantly - not sure how to adapt this to handle multiple files (vectors) in the directory - (not just the single vector I have here) so that all files and folders are represented correctly in the object. Any pointers would be appreciated!
The text was updated successfully, but these errors were encountered: