Skip to content
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

Append to a std::nlohmann::json type #2186

Closed
1 of 3 tasks
Robonics opened this issue Jun 11, 2020 · 3 comments
Closed
1 of 3 tasks

Append to a std::nlohmann::json type #2186

Robonics opened this issue Jun 11, 2020 · 3 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@Robonics
Copy link

I want to add data from multiple JSONs into a singular variable

I want to Parse JSON_1's data into the json data type, then parse JSON_2's data into the same variable, without overwriting the original data (Like an append type operator)

I have tried iterating over the files and using file >> json for each, however the data from the first JSON is overwritten by the next jsons

    std::vector<std::string> cardPaths = getDir("cards/stats/", ".json");
    json cardData;
    std::wstring LoadMsg = L"Loaded:";
    for(auto f_path : cardPaths) {
        std::ifstream(f_path) >> cardData;
        std::cout << f_path << "loaded successfully" << std::endl;
    }

Windows 10 OS and compiler is g++ (Rev3, Built by MSYS2 project) 10.1.0

Library Version

  • latest release version 3.7.3
  • other release - please state the version: ___
  • the develop branch
@nlohmann
Copy link
Owner

nlohmann commented Jun 11, 2020

You can use the update() function for this.

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Jun 11, 2020
@nlohmann
Copy link
Owner

@Robonics
Copy link
Author

Thanks, that worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants