ModelWorks logoModelWorks
JSON Transform

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.

OperationFieldFlavour
filterexpressionCompact comparison (backticks)
mapexpressionJMESPath against item / @
findexpressionJMESPath against item / @
findIndexexpressionJMESPath against item / @
replaceMatchingconditionJMESPath against item / @

Filter Expressions

filter uses a compact comparison syntax of the form:

Text
<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.
JSON
{ "type": "filter", "options": { "expression": "role != `system`" } }
JSON
{ "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 by filter. Use replaceMatching (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:

JSON
{ "type": "find", "options": { "expression": "item.role == `assistant`" } }
{ "type": "find", "options": { "expression": "@.role == `assistant`" } }

map projects each element through the expression:

JSON
{ "type": "map", "options": { "expression": "content" } }

For an input like:

JSON
[
  { "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"):

JSON
{
  "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.
  • filter cannot combine conditions. To express AND/OR, chain multiple filter operations or switch to replaceMatching with a JMESPath condition.
  • The current element's bindings are item and @, not this, $, or the field name.
  • For find/findIndex, an expression that resolves to anything other than Bool(true) is treated as a non-match — so the expression must return a boolean.
On this page

On this page