Skip to main content

JSON Adapter

The JSON adapter provides four pure data manipulation primitives for composing structured outputs and declarative branching in orchestrations. All operations are pure functions with sub-millisecond execution — no IO, no external calls.

Operations

json:merge — Deep Merge

Merges a vector of maps using RFC 7396 JSON Merge Patch semantics. Later values win on key conflict; nested maps merge recursively; null values delete keys.

{
"operation": "json:merge",
"input": {
"values": [
{ "decision": "ESCALATED", "tier": "manager" },
{ "invoice": { "vendor": "Acme Corp", "amount": 15600 } },
{ "policy_passed": true }
]
}
}

Result:

{
"decision": "ESCALATED",
"tier": "manager",
"invoice": { "vendor": "Acme Corp", "amount": 15600 },
"policy_passed": true
}

Use merge to compose outputs from multiple pipeline steps (e.g., LLM decision + invoice data + policy rules).

json:cond — Conditional Selection

Returns the then value of the first case whose when is truthy. Only null and false are falsy — everything else (including 0, "", [], {}) is truthy.

{
"operation": "json:cond",
"input": {
"cases": [
{ "when": false, "then": { "route": "auto-approve" } },
{ "when": true, "then": { "route": "manager", "approver": "J. Martinez" } },
{ "when": false, "then": { "route": "vp" } }
],
"default": { "route": "unknown" }
}
}

Result: { "route": "manager", "approver": "J. Martinez" }

Use cond for declarative branching in orchestrations without invoking an LLM.

json:assoc — Set Value at Path

Sets a value at a path in a map, creating intermediate maps for missing keys. Equivalent to Clojure assoc-in or Lodash _.set.

{
"operation": "json:assoc",
"input": {
"target": { "user": { "name": "alice" } },
"path": ["user", "email"],
"value": "alice@example.com"
}
}

Result: { "user": { "name": "alice", "email": "alice@example.com" } }

The path can be a single string (top-level key) or an array of strings (nested path). Missing intermediate maps are created automatically.

json:select — Pick by Discriminator

Looks up a value in a map of cases by a discriminator key. Like a switch statement.

{
"operation": "json:select",
"input": {
"key": "manager",
"cases": {
"auto": { "decision": "APPROVED" },
"manager": { "decision": "ESCALATED", "target": "J. Martinez" },
"vp": { "decision": "ESCALATED", "target": "VP Finance" }
}
}
}

Result: { "decision": "ESCALATED", "target": "J. Martinez" }

Returns default if the key is not found, or null if no default is provided.

Operations Reference

OperationInputDescription
json:mergevalues (array of maps)RFC 7396 deep merge
json:condcases (array of {when, then}), default?First truthy case
json:assoctarget?, path, valueSet value at nested path
json:selectkey, cases (map), default?Switch on discriminator

Use Cases

  • Pipeline compositionmerge combines outputs from multiple steps into a single result
  • Declarative routingcond and select branch without LLM calls, keeping orchestrations fast and deterministic
  • Data enrichmentassoc adds fields to records before passing them downstream
  • Orchestrator — workflow coordination using these primitives
  • Agents — agents can call JSON operations as tools