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

Unexpected nested arrays from std::vector #886

Closed
hoisunng opened this issue Dec 21, 2017 · 3 comments
Closed

Unexpected nested arrays from std::vector #886

hoisunng opened this issue Dec 21, 2017 · 3 comments
Labels
solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@hoisunng
Copy link

Bug Report

  • What is the issue you have?
    Unexpected nested arrays from std::vector

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?

std::vector<int> v;
json j{v};
std::cout << j << std::endl;
  • What is the expected behavior?
    cout prints: []

  • And what is the actual behavior instead?
    cout prints: [[]]

  • Which compiler and operating system are you using? Is it a supported compiler?
    RHEL7 with GCC 6.3.1

  • Did you use a released version of the library or the version from the develop branch?
    Release Version 2.1.1

@gregmarr
Copy link
Contributor

This is creating a JSON array object containing an empty array. What exactly are you trying to do here? I think you might want json j{json::value_t::array};

@nlohmann
Copy link
Owner

You need to write json j = v;. The braces will be interpreted as arrays themselves, allowing to write code like json j = {1, 2, 3, 4};.

@hoisunng
Copy link
Author

Thanks, that works!

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Dec 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

3 participants