Skip to content

Commit

Permalink
more documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Jun 22, 2015
1 parent f1c9aa2 commit 48545f5
Show file tree
Hide file tree
Showing 14 changed files with 486 additions and 78 deletions.
21 changes: 21 additions & 0 deletions doc/examples/basic_json__CompatibleNumberFloatType.cpp
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';
}
3 changes: 3 additions & 0 deletions doc/examples/basic_json__CompatibleNumberFloatType.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
42.2299995422363
null
23.42
15 changes: 15 additions & 0 deletions doc/examples/basic_json__CompatibleStringType.cpp
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';
}
1 change: 1 addition & 0 deletions doc/examples/basic_json__CompatibleStringType.output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"The quick brown fox jumps over the lazy dog."
21 changes: 21 additions & 0 deletions doc/examples/basic_json__InputIt_InputIt.cpp
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';
}
3 changes: 3 additions & 0 deletions doc/examples/basic_json__InputIt_InputIt.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
["bravo","charly"]
42
{"one":"eins"}
14 changes: 14 additions & 0 deletions doc/examples/basic_json__boolean_t.cpp
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';
}
2 changes: 2 additions & 0 deletions doc/examples/basic_json__boolean_t.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
true
false
15 changes: 15 additions & 0 deletions doc/examples/basic_json__const_int.cpp
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';
}
1 change: 1 addition & 0 deletions doc/examples/basic_json__const_int.output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17
23 changes: 23 additions & 0 deletions doc/examples/operator_deserialize.cpp
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';
}
13 changes: 13 additions & 0 deletions doc/examples/operator_deserialize.output
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!"
}
Loading

0 comments on commit 48545f5

Please sign in to comment.