Skip to content

bmel:json-flatten

Category: JSON · Returns: bmel:string

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

Description

Serializes a nested JSON object into a compact, single-level JSON string using dot-notation keys. Each leaf value is promoted to a top-level key formed by joining the full path of ancestor keys with a dot separator (e.g. {"usage":{"prompt_tokens":42}} becomes {"usage.prompt_tokens":42}). Array elements are indexed as key.0, key.1, … . Scalar inputs are returned as their JSON-serialized string form. Useful for persisting structured LLM payloads (usage objects, tool-call blobs, session metadata) into STRING frame components without losing field granularity. Returns '{}' when the input is null or an empty object.

Arguments

Parameter Type Required Description
object bmel:any The JSON object (or any value) to flatten. Nested objects and arrays are recursively traversed; scalars are serialized directly.

Examples

Usage block as flat keys
bmel:json-flatten({invokeAgent:Response Payload}.$.usage)
Metadata as flat keys
bmel:json-flatten({invokeAgent:Request Payload}.$.metadata)

← Back to BMEL Reference