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 json type as value #1636

Closed
dvfdr43 opened this issue Jun 13, 2019 · 4 comments
Closed

Add json type as value #1636

dvfdr43 opened this issue Jun 13, 2019 · 4 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@dvfdr43
Copy link

dvfdr43 commented Jun 13, 2019

  • Describe what you want to achieve.
    I want to add json type object to other json object

  • Describe what you tried.

std::vector<json> vec;
... // fill vec

json all;
for (auto obj : vec)
    all["inside"].emplace_back(obj):

  • Describe which system (OS, compiler) you are using.
    VS 2019

  • Describe which version of the library you are using (release version, develop branch).
    Latest from the Github (master)

PROBLEM:
but after emplace_back / push_back the all json object is still empty

@jaredgrubb
Copy link
Contributor

I'm not sure I follow. Can you explain what you get and what you were expecting to get?

@nickaein
Copy link
Contributor

Are you sure vec is filled correctly? I tested the following demo code on VS 2019

#include <iostream>
#include <vector>
#include "json.hpp"

int main()
{
    std::vector<nlohmann::json> vec;
    vec.push_back({ "item1", 1 });
    vec.push_back({ "item2", 2 });
    vec.push_back({ "item3", 3 });

    nlohmann::json all;

    for (auto obj : vec)
        all["inside"].emplace_back(obj);

    std::cout << all.dump() << std::endl;
    return 0;
}

and it outputs the following as expected:

{"inside":[["item1",1],["item2",2],["item3",3]]}

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

@dvfdr43 Did @nickaein 's answer help you?

@dvfdr43
Copy link
Author

dvfdr43 commented Jun 20, 2019

Solved, thank you

@dvfdr43 dvfdr43 closed this as completed Jun 20, 2019
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

4 participants