json icon indicating copy to clipboard operation
json copied to clipboard

Allow value(json_pointer) to work with arrays as documented

Open falbrechtskirchinger opened this issue 3 years ago • 3 comments

As discovered here, value(json_pointer) throws an exception, when accessing an array. This deviates from the documented behavior:

try {
   return at(ptr);
} catch(out_of_range) {
   return default_value;
}

Allow value(json_pointer) to work with arrays, update documentation, and update unit tests.

falbrechtskirchinger avatar Sep 20 '22 14:09 falbrechtskirchinger

Would it make sense to also have an overload for integral types just like at or operator[]?

nlohmann avatar Sep 20 '22 15:09 nlohmann

Right, I was going to look at that as well.

Also, if needed, that is probably better suited for the planned "parity PR". I've identified a few functions with "missing" overloads. Adding it to the list.

falbrechtskirchinger avatar Sep 20 '22 15:09 falbrechtskirchinger

Coverage Status

Coverage remained the same at 100.0% when pulling 6724d9450fa8e6d8301d426111799c4084281911 on falbrechtskirchinger:value-json_ptr into f4658de2701f2290baf076bbbd8540260015518c on nlohmann:develop.

coveralls avatar Sep 20 '22 15:09 coveralls