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
6a5db009
Commit
6a5db009
authored
Feb 10, 2019
by
Isaac Nickaein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement contains() to check existence of a key
parent
68ec3eb8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
0 deletions
+66
-0
include/nlohmann/json.hpp
include/nlohmann/json.hpp
+33
-0
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+33
-0
No files found.
include/nlohmann/json.hpp
View file @
6a5db009
...
...
@@ -3957,6 +3957,39 @@ class basic_json
return
is_object
()
?
m_value
.
object
->
count
(
std
::
forward
<
KeyT
>
(
key
))
:
0
;
}
/*!
@brief check the existence of an element in a JSON object
Check whether an element exists in a JSON object with key equivalent to
@a key. If the element is not found or the JSON value is not an object,
false is returned.
@note This method always returns false when executed on a JSON type
that is not an object.
@param[in] key key value to check its existence.
@return true if an element with specified @a key exists. If no such
element with such key is found or the JSON value is not an object,
false is returned.
@complexity Logarithmic in the size of the JSON object.
@since version 3.6.0
*/
template
<
typename
KeyT
>
bool
contains
(
KeyT
&&
key
)
const
{
if
(
is_object
())
{
return
(
m_value
.
object
->
find
(
std
::
forward
<
KeyT
>
(
key
))
!=
m_value
.
object
->
end
());
}
else
{
return
false
;
}
}
/// @}
...
...
single_include/nlohmann/json.hpp
View file @
6a5db009
...
...
@@ -16456,6 +16456,39 @@ class basic_json
return
is_object
()
?
m_value
.
object
->
count
(
std
::
forward
<
KeyT
>
(
key
))
:
0
;
}
/*!
@brief check the existence of an element in a JSON object
Check whether an element exists in a JSON object with key equivalent to
@a key. If the element is not found or the JSON value is not an object,
false is returned.
@note This method always returns false when executed on a JSON type
that is not an object.
@param[in] key key value to check its existence.
@return true if an element with specified @a key exists. If no such
element with such key is found or the JSON value is not an object,
false is returned.
@complexity Logarithmic in the size of the JSON object.
@since version 3.6.0
*/
template
<
typename
KeyT
>
bool
contains
(
KeyT
&&
key
)
const
{
if
(
is_object
())
{
return
(
m_value
.
object
->
find
(
std
::
forward
<
KeyT
>
(
key
))
!=
m_value
.
object
->
end
());
}
else
{
return
false
;
}
}
/// @}
...
...
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