-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
486 additions
and
78 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,21 @@ | ||
#include <json.hpp> | ||
|
||
using namespace nlohmann; | ||
|
||
int main() | ||
{ | ||
// create values of different floating-point types | ||
float f42 = 42.23; | ||
float f_nan = 1.0f / 0.0f; | ||
double f23 = 23.42; | ||
|
||
// create JSON numbers | ||
json j42(f42); | ||
json j_nan(f_nan); | ||
json j23(f23); | ||
|
||
// serialize the JSON numbers | ||
std::cout << j42 << '\n'; | ||
std::cout << j_nan << '\n'; | ||
std::cout << j23 << '\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,3 @@ | ||
42.2299995422363 | ||
null | ||
23.42 |
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,15 @@ | ||
#include <json.hpp> | ||
|
||
using namespace nlohmann; | ||
|
||
int main() | ||
{ | ||
// create a string value | ||
std::string s = "The quick brown fox jumps over the lazy dog."; | ||
|
||
// create a JSON string value | ||
json j = s; | ||
|
||
// serialize the JSON string | ||
std::cout << j << '\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 @@ | ||
"The quick brown fox jumps over the lazy dog." |
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,21 @@ | ||
#include <json.hpp> | ||
|
||
using namespace nlohmann; | ||
|
||
int main() | ||
{ | ||
// create JSON values | ||
json j_array = {"alpha", "bravo", "charly", "delta", "easy"}; | ||
json j_number = 42; | ||
json j_object = {{"one", "eins"}, {"two", "zwei"}}; | ||
|
||
// create copies using iterators | ||
json j_array_range(j_array.begin() + 1, j_array.end() - 2); | ||
json j_number_range(j_number.begin(), j_number.end()); | ||
json j_object_range(j_object.begin(), j_object.find("two")); | ||
|
||
// serialize the values | ||
std::cout << j_array_range << '\n'; | ||
std::cout << j_number_range << '\n'; | ||
std::cout << j_object_range << '\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,3 @@ | ||
["bravo","charly"] | ||
42 | ||
{"one":"eins"} |
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,14 @@ | ||
#include <json.hpp> | ||
|
||
using namespace nlohmann; | ||
|
||
int main() | ||
{ | ||
// create boolean values | ||
json j_truth = true; | ||
json j_falsity = false; | ||
|
||
// serialize the JSON booleans | ||
std::cout << j_truth << '\n'; | ||
std::cout << j_falsity << '\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,2 @@ | ||
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,15 @@ | ||
#include <json.hpp> | ||
|
||
using namespace nlohmann; | ||
|
||
int main() | ||
{ | ||
// an anonymous enum | ||
enum { t = 17 }; | ||
|
||
// create a JSON number from the enum | ||
json j(t); | ||
|
||
// serialize the JSON numbers | ||
std::cout << j << '\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 @@ | ||
17 |
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,23 @@ | ||
#include <json.hpp> | ||
|
||
using namespace nlohmann; | ||
|
||
int main() | ||
{ | ||
// create stream with serialized JSON | ||
std::stringstream ss; | ||
ss << R"({ | ||
"number": 23, | ||
"string": "Hello, world!", | ||
"array": [1, 2, 3, 4, 5], | ||
"boolean": false, | ||
"null": null | ||
})"; | ||
|
||
// create JSON value and read the serialization from the stream | ||
json j; | ||
j << ss; | ||
|
||
// serialize JSON | ||
std::cout << std::setw(2) << j << '\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,13 @@ | ||
{ | ||
"array": [ | ||
1, | ||
2, | ||
3, | ||
4, | ||
5 | ||
], | ||
"boolean": false, | ||
"null": null, | ||
"number": 23, | ||
"string": "Hello, world!" | ||
} |
Oops, something went wrong.