Skip to content

Create an object from path #468

Answered by danielaparker
2rueSid asked this question in Q&A
Discussion options

You must be logged in to vote

In version 0.172.0, you'll be able to write (currently supported on master)

#include <jsoncons/json.hpp>
#include <jsoncons_ext/jsonpointer/jsonpointer.hpp>
#include <jsoncons_ext/jsonpath/jsonpath.hpp>

int main()
{
    try
    {
        std::string str = R"($['b']['c'])"; // or "$.b.c"
        jsoncons::jsonpath::json_location location = jsoncons::jsonpath::json_location::parse(str);

        jsoncons::jsonpointer::json_pointer ptr{};
        for (const auto& element : location)
        {
            if (element.has_name())
                ptr /= element.name();
            else
            {
                ptr /= element.index();
            }
        }

        std::cout << "JSONPoin…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@2rueSid
Comment options

Answer selected by 2rueSid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants