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

Explicit array example in README.md incorrect #867

Closed
xmo opened this issue Dec 10, 2017 · 3 comments
Closed

Explicit array example in README.md incorrect #867

xmo opened this issue Dec 10, 2017 · 3 comments

Comments

@xmo
Copy link

xmo commented Dec 10, 2017

Bug Report

  • What is the issue you have?
    The example in README.md to explicitly construct an array does not work. Maybe a typo/oversight?
// a way to express an _array_ of key/value pairs [["currency", "USD"], ["value", 42.99]]
json array_not_object = { json::array({"currency", "USD"}), json::array({"value", 42.99}) };
  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?
using json = nlohmann::json;
// The original example prints: {"currency":"USD","value":42.99}
json array_not_object = { json::array({"currency", "USD"}), json::array({"value", 42.99}) };
std::cout << array_not_object.dump() << std::endl;
// This seems to work correctly. It prints: [["currency","USD"],["value",42.99]]
json array_not_object_corrected = json::array({ { "currency", "USD" }, { "value", 42.99 } });
std::cout << array_not_object_corrected.dump() << std::endl;
  • What is the expected behavior?
    Constructs an JSON array, i.e. [["currency", "USD"], ["value", 42.99]]

  • And what is the actual behavior instead?
    Constructs an JSON object, {"currency":"USD","value":42.99}

  • Which compiler and operating system are you using? Is it a supported compiler?
    Windows + VS2015. Yes, it is.

  • Did you use a released version of the library or the version from the develop branch?
    Master branch

@nlohmann
Copy link
Owner

Thanks for reporting. I can confirm the behavior for all versions of the library - from 1.0.0-rc1 to the develop version. This is an oversight from me - the code in the README is indeed part of a unit test, but we never checked the results, but only made sure the code does compile.

@nlohmann nlohmann self-assigned this Dec 10, 2017
@nlohmann nlohmann added this to the Release 3.0.0 milestone Dec 10, 2017
nlohmann added a commit that referenced this issue Dec 10, 2017
The example in the documentation on how to "force" an array of arrays was wrong since the first release. Fixed the documentation and added checks for the README unit tests.
@xmo
Copy link
Author

xmo commented Dec 10, 2017

Beautiful. Thank you very much for the wonderful library!

nlohmann added a commit that referenced this issue Dec 11, 2017
@nlohmann
Copy link
Owner

Fixed by merging #868

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants