MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / jsonpointer_select_author

Function jsonpointer_select_author

examples/src/jsonpointer_examples.cpp:87–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85}
86
87void jsonpointer_select_author()
88{
89 auto j = json::parse(R"(
90 [
91 { "category": "reference",
92 "author": "Nigel Rees",
93 "title": "Sayings of the Century",
94 "price": 8.95
95 },
96 { "category": "fiction",
97 "author": "Evelyn Waugh",
98 "title": "Sword of Honour",
99 "price": 12.99
100 }
101 ]
102 )");
103
104 // Using exceptions to report errors
105 try
106 {
107 json result = jsonpointer::get(j, "/1/author");
108 std::cout << "(1) " << result << '\n';
109 }
110 catch (const jsonpointer::jsonpointer_error& e)
111 {
112 std::cout << e.what() << '\n';
113 }
114
115 // Using error codes to report errors
116 std::error_code ec;
117 const json& result = jsonpointer::get(j, "/0/title", ec);
118
119 if (ec)
120 {
121 std::cout << ec.message() << '\n';
122 }
123 else
124 {
125 std::cout << "(2) " << result << '\n';
126 }
127}
128
129void jsonpointer_add_member_to_object()
130{

Callers 1

mainFunction · 0.85

Calls 4

parseFunction · 0.85
getFunction · 0.50
whatMethod · 0.45
messageMethod · 0.45

Tested by

no test coverage detected