• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# basic_json::contains
2
3```cpp
4template<typename KeyT>
5bool contains(KeyT && key) const;
6```
7
8Check whether an element exists in a JSON object with key equivalent to `key`. If the element is not found or the JSON
9value is not an object, `#!cpp false` is returned.
10
11## Template parameters
12
13`KeyT`
14:   A type for an object key other than `basic_json::json_pointer`.
15
16## Parameters
17
18`key` (in)
19:   key value to check its existence.
20
21## Return value
22
23`#!cpp true` if an element with specified `key` exists. If no such element with such key is found or the JSON value is
24not an object, `#!cpp false` is returned.
25
26## Exception safety
27
28Strong exception safety: if an exception occurs, the original value stays intact.
29
30## Complexity
31
32Logarithmic in the size of the JSON object.
33
34## Notes
35
36This method always returns `#!cpp false` when executed on a JSON type that is not an object.
37
38## Example
39
40??? example
41
42    The example shows how `contains()` is used.
43
44    ```cpp
45    --8<-- "examples/contains.cpp"
46    ```
47
48    Output:
49
50    ```json
51    --8<-- "examples/contains.output"
52    ```
53
54## Version history
55
56- Added in version 3.6.0.
57