bag_has_key()

Checks whether a dynamic property bag object contains a given key.

Syntax

bag_has_key(bag,key)

Learn more about syntax conventions.

Parameters

Name Type Required Description
bag dynamic ✔️ The property bag to search.
key string ✔️ The key for which to search. Search for a nested key using the JSONPath notation. Array indexing isn't supported.

Returns

True or false depending on if the key exists in the bag.

Examples

datatable(input: dynamic)
[
    dynamic({'key1' : 123, 'key2': 'abc'}),
    dynamic({'key1' : 123, 'key3': 'abc'}),
]
| extend result = bag_has_key(input, 'key2')

Output

input result
{
"key1": 123,
"key2": "abc"
}
true
{
"key1": 123,
"key3": "abc"
}
false

Search using a JSONPath key

datatable(input: dynamic)
[
    dynamic({'key1': 123, 'key2': {'prop1' : 'abc', 'prop2': 'xyz'}, 'key3': [100, 200]}),
]
| extend result = bag_has_key(input, '$.key2.prop1')

Output

input result
{
"key1": 123,
"key2": {
"prop1": "abc",
"prop2": "xyz"
},
"key3": [
100,
200
]
}
true