Skip to content

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

@Robonics

Description

@Robonics

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions