Skip to content

Explicit array example in README.md incorrect #867

Description

@xmo

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

Activity

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

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions