mirror of
https://github.com/nlohmann/json.git
synced 2025-07-29 23:01:16 +03:00
📝 added documentation
This commit is contained in:
17
doc/examples/contains.cpp
Normal file
17
doc/examples/contains.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create some JSON values
|
||||
json j_object = R"( {"key": "value"} )"_json;
|
||||
json j_array = R"( [1, 2, 3] )"_json;
|
||||
|
||||
// call contains
|
||||
std::cout << std::boolalpha <<
|
||||
"j_object contains 'key': " << j_object.contains("key") << '\n' <<
|
||||
"j_object contains 'another': " << j_object.contains("another") << '\n' <<
|
||||
"j_array contains 'key': " << j_array.contains("key") << std::endl;
|
||||
}
|
1
doc/examples/contains.link
Normal file
1
doc/examples/contains.link
Normal file
@ -0,0 +1 @@
|
||||
<a target="_blank" href="https://wandbox.org/permlink/iHSlXjtjhgO9Q1Tw"><b>online</b></a>
|
3
doc/examples/contains.output
Normal file
3
doc/examples/contains.output
Normal file
@ -0,0 +1,3 @@
|
||||
j_object contains 'key': true
|
||||
j_object contains 'another': false
|
||||
j_array contains 'key': false
|
20
doc/examples/json_pointer__empty.cpp
Normal file
20
doc/examples/json_pointer__empty.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
// different JSON Pointers
|
||||
json::json_pointer ptr0;
|
||||
json::json_pointer ptr1("");
|
||||
json::json_pointer ptr2("/foo");
|
||||
json::json_pointer ptr3("/foo/0");
|
||||
|
||||
// call empty()
|
||||
std::cout << std::boolalpha
|
||||
<< ptr0 << ": " << ptr0.empty() << '\n'
|
||||
<< ptr1 << ": " << ptr1.empty() << '\n'
|
||||
<< ptr2 << ": " << ptr2.empty() << '\n'
|
||||
<< ptr3 << ": " << ptr3.empty() << std::endl;
|
||||
}
|
1
doc/examples/json_pointer__empty.link
Normal file
1
doc/examples/json_pointer__empty.link
Normal file
@ -0,0 +1 @@
|
||||
<a target="_blank" href="https://wandbox.org/permlink/pqG2Q8bmj9SvSX0i"><b>online</b></a>
|
4
doc/examples/json_pointer__empty.output
Normal file
4
doc/examples/json_pointer__empty.output
Normal file
@ -0,0 +1,4 @@
|
||||
"": true
|
||||
"": true
|
||||
"/foo": false
|
||||
"/foo/0": false
|
18
doc/examples/json_pointer__parent_pointer.cpp
Normal file
18
doc/examples/json_pointer__parent_pointer.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
// different JSON Pointers
|
||||
json::json_pointer ptr1("");
|
||||
json::json_pointer ptr2("/foo");
|
||||
json::json_pointer ptr3("/foo/0");
|
||||
|
||||
// call parent_pointer()
|
||||
std::cout << std::boolalpha
|
||||
<< "parent of " << ptr1 << " is " << ptr1.parent_pointer() << '\n'
|
||||
<< "parent of " << ptr2 << " is " << ptr2.parent_pointer() << '\n'
|
||||
<< "parent of " << ptr3 << " is " << ptr3.parent_pointer() << std::endl;
|
||||
}
|
1
doc/examples/json_pointer__parent_pointer.link
Normal file
1
doc/examples/json_pointer__parent_pointer.link
Normal file
@ -0,0 +1 @@
|
||||
<a target="_blank" href="https://wandbox.org/permlink/yweqBQ8bAC6pcn68"><b>online</b></a>
|
3
doc/examples/json_pointer__parent_pointer.output
Normal file
3
doc/examples/json_pointer__parent_pointer.output
Normal file
@ -0,0 +1,3 @@
|
||||
parent of "" is ""
|
||||
parent of "/foo" is ""
|
||||
parent of "/foo/0" is "/foo"
|
21
doc/examples/json_pointer__push_back.cpp
Normal file
21
doc/examples/json_pointer__push_back.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create empty JSON Pointer
|
||||
json::json_pointer ptr;
|
||||
std::cout << ptr << '\n';
|
||||
|
||||
// call push_back()
|
||||
ptr.push_back("foo");
|
||||
std::cout << ptr << '\n';
|
||||
|
||||
ptr.push_back("0");
|
||||
std::cout << ptr << '\n';
|
||||
|
||||
ptr.push_back("bar");
|
||||
std::cout << ptr << '\n';
|
||||
}
|
1
doc/examples/json_pointer__push_back.link
Normal file
1
doc/examples/json_pointer__push_back.link
Normal file
@ -0,0 +1 @@
|
||||
<a target="_blank" href="https://wandbox.org/permlink/kLC7IUvqQ6XJCeG9"><b>online</b></a>
|
4
doc/examples/json_pointer__push_back.output
Normal file
4
doc/examples/json_pointer__push_back.output
Normal file
@ -0,0 +1,4 @@
|
||||
""
|
||||
"/foo"
|
||||
"/foo/0"
|
||||
"/foo/0/bar"
|
Reference in New Issue
Block a user