bmel:json-merge¶
Category: JSON · Returns: bmel:string
Signature
bmel:json-merge(base: bmel:any, overlay: bmel:any)
Description¶
Performs a shallow merge of two JSON objects and returns the result as a JSON string. Keys from bmel:overlay take precedence over keys in bmel:base when both objects share the same key (equivalent to Object.assign in JavaScript or dict | in Python 3.9+). Useful for combining request context and response context into a single STRING field, or for attaching platform metadata to an LLM payload snapshot. Non-object inputs are coerced: scalars and arrays are wrapped in {"value": ...} before merging. Returns '{}' when both inputs are null.
Arguments¶
| Parameter | Type | Required | Description |
|---|---|---|---|
base | bmel:any | The base JSON object. Keys present only here are kept as-is in the output. | |
overlay | bmel:any | The overlay JSON object. Its keys overwrite any matching keys in bmel:base. |
Examples¶
Defaults overridden by the request options
bmel:json-merge({invokeAgent:Request Payload}.$.defaults, {invokeAgent:Request Payload}.$.options)
Request metadata enriched with the response metadata
bmel:json-merge({invokeAgent:Request Payload}.$.metadata, {invokeAgent:Response Payload}.$.metadata)