ModelWorks logoModelWorks
JSON TransformArray

map

Transform each element of an array using JMESPath

map

Projects each element of an array through a JMESPath expression. The current element is exposed as item and @.

Options

OptionTypeRequiredDefaultDescription
expressionstringYesJMESPath expression evaluated against each element.

Example

Input

JSON
[
  { "role": "user",      "content": "Hi" },
  { "role": "assistant", "content": "Hello" }
]

Operation

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

Output

JSON
["Hi", "Hello"]

In a Circuit Step

JSON
{
  "name": "extract_contents",
  "description": "Project each message down to its content string",
  "function": "circuit.core.transform.json",
  "input": {
    "source": "${{ messages }}",
    "operations": [
      { "type": "map", "options": { "expression": "content" } }
    ]
  },
  "outputs": [
    {
      "name": "message_texts",
      "description": "Array of just the message contents",
      "value": "${{ extract_contents.output.transformed_result }}"
    }
  ]
}

Notes & gotchas

  • Errors with map: expected array if the input is not an array.
  • The expression runs in a per-element memory whose root is { "item": <element>, "@": <element> }. You can use either name, plus any JMESPath features.
  • Each evaluation that fails surfaces a map: evaluation failed: ... error and aborts the operation.
  • For multi-field projections, use JMESPath multi-select-hash: "expression": "{ id: id, name: name }".
  • See Expressions for full details and gotchas.
On this page

On this page