Expressions
Expression syntax used by filter, map, find, findIndex, and replaceMatching
Expression Syntax
Several JSON Transform operations take an expression (or condition) string. There are two flavours, and they are not interchangeable.
| Operation | Field | Flavour |
|---|---|---|
filter | expression | Compact comparison (backticks) |
map | expression | JMESPath against item / @ |
find | expression | JMESPath against item / @ |
findIndex | expression | JMESPath against item / @ |
replaceMatching | condition | JMESPath against item / @ |
Filter Expressions
filter uses a compact comparison syntax of the form:
<field> <operator> `<value>`- Supported operators:
==(equals),!=(not equals). - The right-hand value must be wrapped in backticks.
<field>is read directly from each array element, which must be an object.
{ "type": "filter", "options": { "expression": "role != `system`" } }{ "type": "filter", "options": { "expression": "status == `active`" } }Numbers, booleans, and null are stringified before comparison, so count == \5`andenabled == `true`` both work.
Heads up: other JMESPath features (
&&,||, function calls, nested paths) are not supported byfilter. UsereplaceMatching(and accept the cost of a JMESPath evaluation per element) when you need them.
JMESPath Context for map, find, findIndex, replaceMatching
These operations evaluate a JMESPath selector against each array element. Inside the expression, the current element is exposed as both item and @, so you can write either:
{ "type": "find", "options": { "expression": "item.role == `assistant`" } }
{ "type": "find", "options": { "expression": "@.role == `assistant`" } }map projects each element through the expression:
{ "type": "map", "options": { "expression": "content" } }For an input like:
[
{ "role": "user", "content": "hi" },
{ "role": "assistant", "content": "hello" }
]…the result is ["hi", "hello"].
replaceMatching couples a condition (JMESPath) with a with value (selector-evaluated) and a mode ("all" or "first"):
{
"type": "replaceMatching",
"options": {
"condition": "item.role == `system`",
"with": [{ "role": "system", "content": "${{ prompts.system_prompt }}" }],
"mode": "first"
}
}Common Pitfalls
- Backticks are mandatory for literal values (
role == `system`). Quoting with"system"will not parse. filtercannot combine conditions. To express AND/OR, chain multiplefilteroperations or switch toreplaceMatchingwith a JMESPathcondition.- The current element's bindings are
itemand@, notthis,$, or the field name. - For
find/findIndex, an expression that resolves to anything other thanBool(true)is treated as a non-match — so the expression must return a boolean.