Unexpected behavior with foreach for Json::arrayType
Describe the bug bad foreach cycle for arrayValue
To Reproduce
Json::Value j;
j["version"] = "1.0.0";
j["name"] = "arch";
j["arr"] = Json::arrayValue;
j["arr"][5] = "Hello, World!";
for (auto it : j["arr"]) {
std::cout << it << std::endl;
}
in output only "Hello, World"
Expected behavior in output: 5 null's and Hello, World!
Desktop (please complete the following information):
- OS: Win32
- jsoncpp Version: 1.9.5
What you are asking for would also be unexpected, for other people. In JavaScript, "arrays" are just a map who's keys all happen to be integers. This is mimicking that and is thus arguably correct. Arguably, asking for keys that aren't populated should actually return undefined rather than null. That said JSON is not actual JavaScript so that argument isn't conclusive. At the same time, I don't think the JSON standard say anything at all about anything past syntax.
What should happen with iteration if other keys were added?:
-5"5""foo"