-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Closed
Labels
documentationsolution: proposed fixa fix for the issue has been proposed and waits for confirmationa fix for the issue has been proposed and waits for confirmation
Milestone
Description
Description
When parsing the following json, operator[key]
and value(key)
return different results despite 'key' being a valid field.
{
"array": [
{
"id": 3024667086235176575
},
{
"id": 5894322762133244432
},
{
"id": 7912588194672682964
},
{
"id": 16577926123393930376
}
]
}
In this case j["array"][0]["id"] != j["array"][0].value("id",0)
.
Reproduction steps
See minimal example below.
Expected vs. actual results
If a key exists in a json object, I would expect j[key]
to return the same value as j.value(key, default)
.
Minimal code example
Here is a minimal program that reproduces the bug:
#include "json.hpp"
#include <string>
int main(int argc, char* argv[])
{
std::string s = R"({
"array": [
{
"id": 3024667086235176575
},
{
"id": 5894322762133244432
},
{
"id": 7912588194672682964
},
{
"id": 16577926123393930376
}
]
})";
json j = json::parse(s);
json& arr = j["array"];
json& arr0 = arr[0];
uint64_t idTest0 = arr0["id"];
uint64_t idTest1 = arr0.value("id", 0);
// Expected idTest0 == idTest1 == 3024667086235176575
// Got idTest0 == 3024667086235176575
// idTest1 == 18446744071677218431
return 0;
}
Error messages
Compiler and operating system
msvc (VS2022), windows 11
Library version
json-3.11.3
Validation
- The bug also occurs if the latest version from the
develop
branch is used. - I can successfully compile and run the unit tests.
Metadata
Metadata
Assignees
Labels
documentationsolution: proposed fixa fix for the issue has been proposed and waits for confirmationa fix for the issue has been proposed and waits for confirmation