Share via


bag_has_key ()

檢查動態屬性包物件是否包含指定的索引鍵。

Syntax

bag_has_key(,關鍵)

深入瞭解 語法慣例

參數

名稱 類型 必要 Description
bag dynamic ✔️ 要搜尋的屬性包。
key string ✔️ 要搜尋的索引鍵。 使用 JSONPath 表示法搜尋巢狀索引鍵。 不支持陣列索引編製。

傳回

True 或 false,視密鑰是否存在於包中而定。

範例

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

輸出

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

使用 JSONPath 金鑰搜尋

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

輸出

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