Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
d08e013d
Commit
d08e013d
authored
Jul 25, 2016
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improved documentation
parent
369671f0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
93 additions
and
2 deletions
+93
-2
doc/examples/basic_json__value_ptr.cpp
doc/examples/basic_json__value_ptr.cpp
+29
-0
doc/examples/basic_json__value_ptr.link
doc/examples/basic_json__value_ptr.link
+1
-0
doc/examples/basic_json__value_ptr.output
doc/examples/basic_json__value_ptr.output
+1
-0
src/json.hpp
src/json.hpp
+31
-1
src/json.hpp.re2c
src/json.hpp.re2c
+31
-1
No files found.
doc/examples/basic_json__value_ptr.cpp
0 → 100644
View file @
d08e013d
#include <json.hpp>
using
json
=
nlohmann
::
json
;
int
main
()
{
// create a JSON object with different entry types
json
j
=
{
{
"integer"
,
1
},
{
"floating"
,
42.23
},
{
"string"
,
"hello world"
},
{
"boolean"
,
true
},
{
"object"
,
{{
"key1"
,
1
},
{
"key2"
,
2
}}},
{
"array"
,
{
1
,
2
,
3
}}
};
// access existing values
int
v_integer
=
j
.
value
(
"/integer"
_json_pointer
,
0
);
double
v_floating
=
j
.
value
(
"/floating"
_json_pointer
,
47.11
);
// access nonexisting values and rely on default value
std
::
string
v_string
=
j
.
value
(
"/nonexisting"
_json_pointer
,
"oops"
);
bool
v_boolean
=
j
.
value
(
"/nonexisting"
_json_pointer
,
false
);
// output values
std
::
cout
<<
std
::
boolalpha
<<
v_integer
<<
" "
<<
v_floating
<<
" "
<<
v_string
<<
" "
<<
v_boolean
<<
"
\n
"
;
}
doc/examples/basic_json__value_ptr.link
0 → 100644
View file @
d08e013d
<a target="_blank" href="http://melpon.org/wandbox/permlink/K4L4D6nibuGXbjfd"><b>online</b></a>
\ No newline at end of file
doc/examples/basic_json__value_ptr.output
0 → 100644
View file @
d08e013d
1 42.23 oops false
src/json.hpp
View file @
d08e013d
...
...
@@ -974,7 +974,9 @@ class basic_json
@since version 1.0.0
*/
using
parser_callback_t
=
std
::
function
<
bool
(
int
depth
,
parse_event_t
event
,
basic_json
&
parsed
)
>
;
using
parser_callback_t
=
std
::
function
<
bool
(
int
depth
,
parse_event_t
event
,
basic_json
&
parsed
)
>
;
//////////////////
...
...
@@ -3716,6 +3718,21 @@ class basic_json
/*!
@brief access specified object element via JSON Pointer with default value
Returns either a copy of an object's element at the specified key @a key
or a given default value if no element with key @a key exists.
The function is basically equivalent to executing
@code {.cpp}
try {
return at(ptr);
} catch(std::out_of_range) {
return default_value;
}
@endcode
@note Unlike @ref at(const json_pointer&), this function does not throw
if the given key @a key was not found.
@param[in] ptr a JSON pointer to the element to access
@param[in] default_value the value to return if @a ptr found no value
...
...
@@ -3724,6 +3741,19 @@ class basic_json
JSON arrays. Note the type of the expected value at @a key and the default
value @a default_value must be compatible.
@return copy of the element at key @a key or @a default_value if @a key
is not found
@throw std::domain_error if JSON is not an object; example: `"cannot use
value() with null"`
@complexity Logarithmic in the size of the container.
@liveexample{The example below shows how object elements can be queried
with a default value.,basic_json__value_ptr}
@sa @ref operator[](const json_ptr&) for unchecked access by reference
@since version 2.0.2
*/
template
<
class
ValueType
,
typename
...
...
src/json.hpp.re2c
View file @
d08e013d
...
...
@@ -974,7 +974,9 @@ class basic_json
@since version 1.0.0
*/
using parser_callback_t = std::function<bool(int depth, parse_event_t event, basic_json& parsed)>;
using parser_callback_t = std::function<bool(int depth,
parse_event_t event,
basic_json& parsed)>;
//////////////////
...
...
@@ -3716,6 +3718,21 @@ class basic_json
/*!
@brief access specified object element via JSON Pointer with default value
Returns either a copy of an object's element at the specified key @a key
or a given default value if no element with key @a key exists.
The function is basically equivalent to executing
@code {.cpp}
try {
return at(ptr);
} catch(std::out_of_range) {
return default_value;
}
@endcode
@note Unlike @ref at(const json_pointer&), this function does not throw
if the given key @a key was not found.
@param[in] ptr a JSON pointer to the element to access
@param[in] default_value the value to return if @a ptr found no value
...
...
@@ -3724,6 +3741,19 @@ class basic_json
JSON arrays. Note the type of the expected value at @a key and the default
value @a default_value must be compatible.
@return copy of the element at key @a key or @a default_value if @a key
is not found
@throw std::domain_error if JSON is not an object; example: `"cannot use
value() with null"`
@complexity Logarithmic in the size of the container.
@liveexample{The example below shows how object elements can be queried
with a default value.,basic_json__value_ptr}
@sa @ref operator[](const json_ptr&) for unchecked access by reference
@since version 2.0.2
*/
template <class ValueType, typename
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment