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

Add array support for update() function #1751

Closed
mrakh opened this issue Sep 13, 2019 · 3 comments
Closed

Add array support for update() function #1751

mrakh opened this issue Sep 13, 2019 · 3 comments
Labels
kind: enhancement/improvement state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated

Comments

@mrakh
Copy link

mrakh commented Sep 13, 2019

I think it would be nice to add functionality to the update() function that allows one to update an array's contents with an object that has integer keys, like so:

nlohmann::json myarr = { 5, 4, 3, 2, 1 };
myarr.update({ { "1", 40 }, { "4", 10 } });
std::cout << myarr.dump() << std::endl;
// Should output [5,40,3,2,10]
@tete17
Copy link
Contributor

tete17 commented Sep 15, 2019

Why not used a simple function like this?

void updateJson(nlohmann::json& j, const std::vector<std::pait<int,int>>& list)
{
    if(!j.is_array()) thorw ...;
    for (const auto& pair : list)
    {
        j[pair.first] = pair.second;
    }
}

Do you need your update function to take strings on the index argument?

@nlohmann
Copy link
Owner

This is an odd syntax to provide array indices as strings. In any case, this function could be realized without changing the library's API.

@stale
Copy link

stale bot commented Oct 16, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Oct 16, 2019
@stale stale bot closed this as completed Oct 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement/improvement state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated
Projects
None yet
Development

No branches or pull requests

3 participants