Skip to content

Latest commit

 

History

History
51 lines (40 loc) · 1 KB

contains.md

File metadata and controls

51 lines (40 loc) · 1 KB

jsoncons::jsonpointer::contains

#include <jsoncons_ext/jsonpointer/jsonpointer.hpp>

template<class Json>
bool contains(const Json& doc, const Json::string_view_type& location);

Return value

Returns true if the json doc contains the given JSON Pointer, otherwise `false'

Examples

Examples from RFC6901

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

namespace jsonpointer = jsoncons::jsonpointer;

int main()
{
    // Example from RFC 6901
    auto j = jsoncons::json::parse(R"(
       {
          "foo": ["bar", "baz"],
          "": 0,
          "a/b": 1,
          "c%d": 2,
          "e^f": 3,
          "g|h": 4,
          "i\\j": 5,
          "k\"l": 6,
          " ": 7,
          "m~n": 8
       }
    )");

    std::cout << "(1) " << jsonpointer::contains(j, "/foo/0") << std::endl;
    std::cout << "(2) " << jsonpointer::contains(j, "e^g") << std::endl;
}

Output:

(1) true
(2) false