Skip to content

bmel:json-depth

Category: JSON · Returns: bmel:integer

Signature
bmel:json-depth(object: bmel:any)

Description

Returns the maximum nesting depth of a JSON object or array. A flat object {"a":1} has depth 1. An object with one level of nested children has depth 2, and so on. Useful for detecting abnormally deep payloads that may indicate prompt injection via recursive JSON structures, runaway tool-call nesting in agentic sessions, or malformed LLM outputs. Returns 0 for scalars and null.

Arguments

Parameter Type Required Description
object bmel:any The JSON object, array, or string to measure. If a string is provided it is parsed first.

Examples

Nesting depth of the tool arguments
bmel:json-depth({invokeAgent:Request Payload}.$.arguments)
Abnormally deep tool arguments
bmel:json-depth({invokeAgent:Request Payload}.$.arguments) > 10

← Back to BMEL Reference