-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added functions is_structured() and is_primitive() - updated documentation - updated test cases
- Loading branch information
Showing
11 changed files
with
396 additions
and
98 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,25 @@ | ||
#include <json.hpp> | ||
|
||
using namespace nlohmann; | ||
|
||
int main() | ||
{ | ||
// create JSON values | ||
json j_null; | ||
json j_boolean = true; | ||
json j_number_integer = 17; | ||
json j_number_float = 23.42; | ||
json j_object = {{"one", 1}, {"two", 2}}; | ||
json j_array = {1, 2, 4, 8, 16}; | ||
json j_string = "Hello, world"; | ||
|
||
// call is_primitive() | ||
std::cout << std::boolalpha; | ||
std::cout << j_null.is_primitive() << '\n'; | ||
std::cout << j_boolean.is_primitive() << '\n'; | ||
std::cout << j_number_integer.is_primitive() << '\n'; | ||
std::cout << j_number_float.is_primitive() << '\n'; | ||
std::cout << j_object.is_primitive() << '\n'; | ||
std::cout << j_array.is_primitive() << '\n'; | ||
std::cout << j_string.is_primitive() << '\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,7 @@ | ||
true | ||
true | ||
true | ||
true | ||
false | ||
false | ||
true |
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,25 @@ | ||
#include <json.hpp> | ||
|
||
using namespace nlohmann; | ||
|
||
int main() | ||
{ | ||
// create JSON values | ||
json j_null; | ||
json j_boolean = true; | ||
json j_number_integer = 17; | ||
json j_number_float = 23.42; | ||
json j_object = {{"one", 1}, {"two", 2}}; | ||
json j_array = {1, 2, 4, 8, 16}; | ||
json j_string = "Hello, world"; | ||
|
||
// call is_structured() | ||
std::cout << std::boolalpha; | ||
std::cout << j_null.is_structured() << '\n'; | ||
std::cout << j_boolean.is_structured() << '\n'; | ||
std::cout << j_number_integer.is_structured() << '\n'; | ||
std::cout << j_number_float.is_structured() << '\n'; | ||
std::cout << j_object.is_structured() << '\n'; | ||
std::cout << j_array.is_structured() << '\n'; | ||
std::cout << j_string.is_structured() << '\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,7 @@ | ||
false | ||
false | ||
false | ||
false | ||
true | ||
true | ||
false |
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,34 @@ | ||
#include <json.hpp> | ||
|
||
using namespace nlohmann; | ||
|
||
int main() | ||
{ | ||
// create JSON values | ||
json j_null; | ||
json j_boolean = true; | ||
json j_number_integer = 17; | ||
json j_number_float = 23.42; | ||
json j_object = {{"one", 1}, {"two", 2}}; | ||
json j_array = {1, 2, 4, 8, 16}; | ||
json j_string = "Hello, world"; | ||
|
||
// call operator value_t() | ||
json::value_t t_null = j_null; | ||
json::value_t t_boolean = j_boolean; | ||
json::value_t t_number_integer = j_number_integer; | ||
json::value_t t_number_float = j_number_float; | ||
json::value_t t_object = j_object; | ||
json::value_t t_array = j_array; | ||
json::value_t t_string = j_string; | ||
|
||
// print types | ||
std::cout << std::boolalpha; | ||
std::cout << (t_null == json::value_t::null) << '\n'; | ||
std::cout << (t_boolean == json::value_t::boolean) << '\n'; | ||
std::cout << (t_number_integer == json::value_t::number_integer) << '\n'; | ||
std::cout << (t_number_float == json::value_t::number_float) << '\n'; | ||
std::cout << (t_object == json::value_t::object) << '\n'; | ||
std::cout << (t_array == json::value_t::array) << '\n'; | ||
std::cout << (t_string == json::value_t::string) << '\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,7 @@ | ||
true | ||
true | ||
true | ||
true | ||
true | ||
true | ||
true |
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,25 @@ | ||
#include <json.hpp> | ||
|
||
using namespace nlohmann; | ||
|
||
int main() | ||
{ | ||
// create JSON values | ||
json j_null; | ||
json j_boolean = true; | ||
json j_number_integer = 17; | ||
json j_number_float = 23.42; | ||
json j_object = {{"one", 1}, {"two", 2}}; | ||
json j_array = {1, 2, 4, 8, 16}; | ||
json j_string = "Hello, world"; | ||
|
||
// call type() | ||
std::cout << std::boolalpha; | ||
std::cout << (j_null.type() == json::value_t::null) << '\n'; | ||
std::cout << (j_boolean.type() == json::value_t::boolean) << '\n'; | ||
std::cout << (j_number_integer.type() == json::value_t::number_integer) << '\n'; | ||
std::cout << (j_number_float.type() == json::value_t::number_float) << '\n'; | ||
std::cout << (j_object.type() == json::value_t::object) << '\n'; | ||
std::cout << (j_array.type() == json::value_t::array) << '\n'; | ||
std::cout << (j_string.type() == json::value_t::string) << '\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,7 @@ | ||
true | ||
true | ||
true | ||
true | ||
true | ||
true | ||
true |
Oops, something went wrong.