boostorg / json

A C++11 library for parsing and serializing JSON to and from a DOM container in memory.
https://boost.org/libs/json
Boost Software License 1.0
434 stars 97 forks source link

[Feature request] Path support in subscript. #685

Closed kilasuelika closed 2 years ago

kilasuelika commented 2 years ago

I'm wondering if there will be path support in subscript:

//Json object
boost::json::object obj;
boost::json::object sub;
sub["name"] = "child";
obj["child"] = sub;

//subscript.
obj["child"].as_object()["sub"];  //Current.
obj["child/sub"];  //What I'm suggest.
vinniefalco commented 2 years ago

With the syntax that you suggest, there would be a cost with checking for a forward slash that would be paid for all users - even those that are not using the path syntax. Have you had a look at these examples?

https://github.com/boostorg/json/blob/56eaebf1cb1f6ff767cf9a2baa6920c0d2db0022/example/path.cpp#L49

or

https://github.com/boostorg/json/blob/56eaebf1cb1f6ff767cf9a2baa6920c0d2db0022/example/proxy.cpp#L61

?

grisumbras commented 2 years ago

Note, that we are working on JSON Pointer implementation (https://tools.ietf.org/html/rfc6901). #480

grisumbras commented 2 years ago

@kilasuelika is JSON Pointer enough for you? Documentation is here: https://www.boost.org/doc/libs/1_79_0/libs/json/doc/html/json/dom/nested_access.html

kilasuelika commented 2 years ago

@kilasuelika is JSON Pointer enough for you? Documentation is here: https://www.boost.org/doc/libs/1_79_0/libs/json/doc/html/json/dom/nested_access.html

It's exactly what I want. Thank you.