Use the bag_has_key function in APL to check whether a dynamic property bag contains a specific key. This is helpful when your data includes semi-structured or nested fields encoded as dynamic objects, such as JSON-formatted logs or telemetry metadata. You often encounter property bags in observability data where log entries, spans, or alerts carry key–value metadata. Use bag_has_key to filter, conditionally process, or join such records based on the existence of specific keys, without needing to extract the values themselves.

For users of other query languages

If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.
In Splunk SPL, you often check whether a key exists in a JSON object using spath and conditional logic. APL simplifies this with bag_has_key, which returns a boolean directly and avoids explicit parsing.
| eval hasKey=if(isnull(spath(data, "keyName")), false, true)
ANSI SQL doesn’t include native support for property bags or dynamic fields. You typically use JSON functions to access keys in JSON-formatted strings. In APL, dynamic fields are first-class, and bag_has_key provides direct support for key existence checks.
SELECT *
FROM logs
WHERE JSON_EXTRACT(json_column, '$.keyName') IS NOT NULL

Usage

Syntax

bag_has_key(bag: dynamic, key: string) 

Parameters

NameTypeDescription
bagdynamicA dynamic value representing a property bag (e.g., JSON object).
keystringThe key to check for within the property bag.

Returns

Returns a bool value:
  • true if the specified key exists in the property bag
  • false otherwise

Use case examples

Use bag_has_key to filter log entries that include a specific metadata key embedded in a dynamic object.Query
['sample-http-logs']
| extend metadata = bag_pack('source', 'cdn', 'env', 'prod')
| where bag_has_key(metadata, 'env')
| project _time, id, method, uri, status, metadata
Run in PlaygroundOutput
_timeidmethoduristatusmetadata
2025-05-27T12:30Zu123GET/login200{‘source’:‘cdn’,‘env’:‘prod’}
2025-05-27T12:31Zu124POST/cart/checkout500{‘source’:‘cdn’,‘env’:‘prod’}
The query filters logs where the synthetic metadata bag includes the key 'env'.
  • bag_keys: Returns all keys in a dynamic property bag. Use it when you need to enumerate available keys.
  • bag_pack: Converts a list of key-value pairs to a dynamic property bag. Use when you need to build a bag.