Transform Data
使用强大的 JSONata 表达式转换输入载荷。
针对输入 payload 求值 JSONata 表达式;结果替换 payload。
这是工作流中进行数据映射和结构转换的主要工具。它可以对输入 JSON 进行重塑、过滤,并通过数学计算生成新值。
功能特性:
- 完整支持 JSONata 语法。
- 可访问整个工作流上下文。
- 支持查询和聚合数据。
适用场景:
- 将 API 响应映射到内部模型。
- 过滤列表中的条目(例如
items[price > 50])。 - 计算合计(例如
$sum(items.price))。
工作原理
- 解析配置:
expr中的{{ }}块先由 Expression Engine 求值;纯 JSONata 文本保持不变。 expr为空时失败。- 若
expr解析为对象或数组(整值{{ }}返回数据),则直接以该值为结果,跳过 JSONata。 - 否则将字符串编译为 JSONata 2,并以 payload 为根求值:
order.total、$sum(items.price)、{ "id": order_id, "lines": $count(items) }。 - 通过
out将结果作为新的 payload 返回。
在工作流中
节点在工作流文件(draft_nodes[])中的写法,以及一次成功运行的 envelope。
{
"node_id": "node-shape-order",
"label": "Shape order",
"operator_slug": "data.transform",
"operator_version": "1.0.0",
"config": {
"expr": "{ \"id\": order_id, \"total\": $sum(items.price), \"lines\": $count(items) }"
}
}{
"ok": true,
"data": {
"id": "ord_123",
"total": 42.5,
"lines": 2
},
"port": "out"
}配置
-
exprstring 必填 支持表达式 -
要求值的 JSONata 表达式。其结果即为输出载荷。
配置中会显示通用执行设置,但该节点目前不执行重试(retryOnFail、maxTries)。所有节点均未实现 continueOnFail。
代码中的行为
除 schema 描述之外,实现代码对这些键的实际处理。
-
expr - JSONata 中没有绑定 Expression Engine 变量:
$json.total的结果为 undefined。请使用 payload 路径和 JSONata 内置函数($now()、$sum、$map),或在混合文本中用{{ }}嵌入引擎值(插入其字符串形式):{ "run": "{{ $execution.id }}", "total": $sum(items.price) }。混合文本中出错的{{ }}会在表达式里变成[ERROR: <message>]。
输出端口
out 默认 表达式已求值。
{
"id": "ord_123",
"total": 42.5,
"lines": 2
}error expr 为空或 JSONata 出错。
{
"ok": false,
"errors": [
"Transform Error: Unexpected end of expression"
],
"port": "error"
}在表达式中
后续节点可通过 $("Transform Data").item.json.<路径> 读取此节点输出中的内容(请把 Transform Data 换成你的节点标签)。Editor 标记工作流编辑器在 Previous Nodes 中提示的路径(输出契约);Worker 标记 worker 实际通过 out 返回的路径,依据“端口”一节所示的输出。
| 表达式 | Editor | Worker |
|---|---|---|
$("Transform Data").item.json.result | — | |
$("Transform Data").item.json.id | — | |
$("Transform Data").item.json.total | — | |
$("Transform Data").item.json.lines | — |
— Editor: 编辑器会提示它,但 worker 并不返回:读取结果为 undefined。
— Worker: worker 会返回它,但编辑器不会提示:请手动输入。对象内部的键可能取决于你的数据或配置(例如每个标签一个键)。
错误
| 消息 | 端口 | 原因与处理 |
|---|---|---|
Transformation expression is required | error | expr 缺失,或其 {{ }} 解析为空值。 |
Transform Error: <JSONata message> | error | JSONata 语法或运行时错误,例如 Unexpected end of expression。 |
Transform Error: path.charAt is not a function | error | 整值 {{ }} 返回了数字或布尔值,它既不是 JSONata 文本也不是数据。 |
输入契约
-
payloadobject 可选
输出契约
-
resultobject 可选
契约(JSON Schema)
与编排器声明完全一致的定义。All 是完整的 *.definition.js;可与上方各节对照,找出文档与 schema 之间的差异。发布前可用它校验节点。
{
"slug": "data.transform",
"name": "Transform Data",
"category": "data",
"version": "1.0.0",
"description": "Transforms the input payload using powerful JSONata expressions.\n\n This is the primary tool for data mapping and structural transformation logic within the workflow. It allows you to reshape, filter, and mathematically compute new values from the input JSON.\n\n **Features:**\n - Full JSONata syntax support.\n - Access to the entire workflow context.\n - Capability to query and aggregate data.\n\n **Use Cases:**\n - Mapping an API response to an internal model.\n - Filtering items from a list (e.g., `items[price > 50]`).\n - Calculating totals (e.g., `$sum(items.price)`).",
"capabilities": [
"transform",
"jsonata",
"mapping",
"utils"
],
"config_schema": {
"type": "object",
"required": [
"expr"
],
"properties": {
"expr": {
"type": "string",
"title": "Transformation Expression",
"format": "expression",
"description": "The JSONata expression to evaluate. The result becomes the output payload."
},
"execution": {
"type": "object",
"title": "Execution Settings",
"properties": {
"alwaysOutputData": {
"type": "boolean",
"title": "Always Output Data",
"description": "Always output data, even on error (if configured).",
"default": false
},
"retryOnFail": {
"type": "boolean",
"title": "Retry On Fail",
"description": "Retry the execution if it fails.",
"default": false
},
"maxTries": {
"type": "integer",
"title": "Max Retries",
"description": "Number of retries.",
"default": 3,
"displayOptions": {
"show": {
"retryOnFail": [
true
]
}
}
},
"waitBetweenTries": {
"type": "integer",
"title": "Wait Between Retries (ms)",
"default": 1000,
"displayOptions": {
"show": {
"retryOnFail": [
true
]
}
}
},
"continueOnFail": {
"type": "boolean",
"title": "Continue On Fail",
"description": "Do not crash workflow on error.",
"default": false
},
"timeout_ms": {
"type": "integer",
"title": "Timeout (ms)",
"description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
"default": 300000
}
}
}
}
},
"input_contract_schema": {
"type": "object",
"description": "Any JSON payload.",
"properties": {
"payload": {
"type": "object"
}
}
},
"output_contract_schema": {
"type": "object",
"description": "The result of the JSONata evaluation.",
"properties": {
"result": {
"type": "object"
}
}
},
"ports": [
{
"port_id": "out",
"label": "Output",
"is_default": true,
"description": "Transformation result"
},
{
"port_id": "error",
"label": "Error",
"description": "Expression failed"
}
],
"execution_mode": "sync",
"tags": [
"transform",
"jsonata",
"map"
],
"is_stateful": false,
"publisher": {
"identity": "org_link_loom",
"profile": {
"name": "Link Loom",
"verified": true,
"url": "https://me.veripass.com/link-loom",
"logo_url": null
}
}
}{
"type": "object",
"required": [
"expr"
],
"properties": {
"expr": {
"type": "string",
"title": "Transformation Expression",
"format": "expression",
"description": "The JSONata expression to evaluate. The result becomes the output payload."
},
"execution": {
"type": "object",
"title": "Execution Settings",
"properties": {
"alwaysOutputData": {
"type": "boolean",
"title": "Always Output Data",
"description": "Always output data, even on error (if configured).",
"default": false
},
"retryOnFail": {
"type": "boolean",
"title": "Retry On Fail",
"description": "Retry the execution if it fails.",
"default": false
},
"maxTries": {
"type": "integer",
"title": "Max Retries",
"description": "Number of retries.",
"default": 3,
"displayOptions": {
"show": {
"retryOnFail": [
true
]
}
}
},
"waitBetweenTries": {
"type": "integer",
"title": "Wait Between Retries (ms)",
"default": 1000,
"displayOptions": {
"show": {
"retryOnFail": [
true
]
}
}
},
"continueOnFail": {
"type": "boolean",
"title": "Continue On Fail",
"description": "Do not crash workflow on error.",
"default": false
},
"timeout_ms": {
"type": "integer",
"title": "Timeout (ms)",
"description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
"default": 300000
}
}
}
}
}{
"type": "object",
"description": "Any JSON payload.",
"properties": {
"payload": {
"type": "object"
}
}
}{
"type": "object",
"description": "The result of the JSONata evaluation.",
"properties": {
"result": {
"type": "object"
}
}
}[
{
"port_id": "out",
"label": "Output",
"is_default": true,
"description": "Transformation result"
},
{
"port_id": "error",
"label": "Error",
"description": "Expression failed"
}
]执行
- 执行方式
sync- 有状态
- 否
- 重试(
retryOnFail) - 否
- 能力
transformjsonatamappingutils- 标签
transformjsonatamap
说明与限制
- 若结果为 undefined(路径没有匹配)或假值,引擎会保存整个信封
{ ok, port }作为输出,而不是结果。 - 之前的 payload 会被替换;如需之前的数据,请在混合文本中使用
{{ $("Node").item.json.field }}。 - 当返回的信封没有
data(或data为假值)时,引擎会把整个信封作为节点输出:经error端口时,下一个节点收到的 payload 是{ ok: false, errors: [...], port: "error" }。
已对照编排器代码核实 · 31e874b · 2026-11-26