-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/json_pointer_contains' into develop
- Loading branch information
Showing
7 changed files
with
338 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <iostream> | ||
#include <nlohmann/json.hpp> | ||
|
||
using json = nlohmann::json; | ||
|
||
int main() | ||
{ | ||
// create a JSON value | ||
json j = | ||
{ | ||
{"number", 1}, {"string", "foo"}, {"array", {1, 2}} | ||
}; | ||
|
||
std::cout << std::boolalpha | ||
<< j.contains("/number"_json_pointer) << '\n' | ||
<< j.contains("/string"_json_pointer) << '\n' | ||
<< j.contains("/string"_json_pointer) << '\n' | ||
<< j.contains("/array"_json_pointer) << '\n' | ||
<< j.contains("/array/1"_json_pointer) << '\n' | ||
<< j.contains("/array/-"_json_pointer) << '\n' | ||
<< j.contains("/array/4"_json_pointer) << '\n' | ||
<< j.contains("/baz"_json_pointer) << std::endl; | ||
|
||
// out_of_range.106 | ||
try | ||
{ | ||
// try to use an array index with leading '0' | ||
j.contains("/array/01"_json_pointer); | ||
} | ||
catch (json::parse_error& e) | ||
{ | ||
std::cout << e.what() << '\n'; | ||
} | ||
|
||
// out_of_range.109 | ||
try | ||
{ | ||
// try to use an array index that is not a number | ||
j.contains("/array/one"_json_pointer); | ||
} | ||
catch (json::parse_error& e) | ||
{ | ||
std::cout << e.what() << '\n'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<a target="_blank" href="https://wandbox.org/permlink/3TJ79OzHP4vmN1Nb"><b>online</b></a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
true | ||
true | ||
true | ||
true | ||
true | ||
false | ||
false | ||
false | ||
[json.exception.parse_error.106] parse error: array index '01' must not begin with '0' | ||
[json.exception.parse_error.109] parse error: array index 'one' is not a number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.