Generators
新生成的随机标识符。
每个示例都在已部署的表达式引擎上、基于页面末尾的示例上下文运行过。
$uuid
随机的第 4 版 UUID,36 个字符,采用 8-4-4-4-12 的十六进制格式。它是属性而非函数:写 $uuid,不要写 $uuid()。每次读取都产生新值,即使在同一表达式中读取两次也是如此。
示例
结果 string 随机:每次运行都会生成新值
结果 string 随机:每次运行都会生成新值
错误
| 消息 | 原因与解决方法 |
|---|---|
$uuid is not a function | 以 $uuid() 的形式调用了它。请去掉括号。 |
说明
- 多个节点需要同一个 id 时,只生成一次(例如在
data.transform中),再用$('…')从该节点读取。
在 JSONata 中 $$uuid
$randomId
返回 prefix 加上 length 个随机十六进制字符(0-9、a-f)。适用于便于人工识读的引用编号;标准标识符请使用 $uuid。
参数
-
optionsobject 必填 - 务必传入一个对象,即使是空对象:不传则
$randomId()会失败。 -
options.lengthnumber 可选 默认15 - 随机字符的个数(最多 512)。
-
options.prefixstring 可选 默认'id-' - 放在随机字符前面的文本。
返回
string prefix + length 个十六进制字符。
示例
结果 string 随机:每次运行都会生成新值
结果 string 随机:每次运行都会生成新值
不传选项对象会失败。
抛出
错误
| 消息 | 原因与解决方法 |
|---|---|
Cannot destructure property 'length' of 'undefined' as it is undefined. | 调用时没有传选项对象。至少传入 {}。 |
在 JSONata 中 $$randomId({ "length": 8, "prefix": "ord-" })
示例上下文
示例基于以下数据运行:当前节点的输入($json)、已运行的节点($(…))、本次运行的 ID 以及当前节点。时钟固定为 2026-11-26T14:30:00.000Z,服务器时区为 UTC,因此各页面中 $now 与 $today 的值都相同。
当前节点的输入
{
"$json": {
"body": {
"order_id": "ord_1042",
"email": "ana.perez@example.com",
"customer": {
"name": "Ana Pérez",
"segment": "gold"
},
"priority": "",
"items": [
{
"sku": "A-100",
"qty": 2,
"price": 10.5
},
{
"sku": "B-200",
"qty": 0,
"price": 4
},
{
"sku": "C-300",
"qty": 1,
"price": 25
}
],
"tags": [
"new",
"web",
"new"
],
"created_at": "2026-11-25T09:15:00Z"
},
"headers": {
"content-type": "application/json"
},
"query": {},
"method": "POST"
}
} 已运行的节点(标签 → 输出)
{
"Webhook Receiver": "= $json",
"Normalize input": {
"correlation_id": "c-7f3a",
"channel": "web"
},
"Classify": {
"label": "billing",
"confidence": 0.92
}
} 运行与当前节点
{
"$execution": {
"id": "fir-xxxx",
"flow_instance_id": "fi-xxxx",
"flow_definition_id": "fd-xxxx",
"flow_version_id": "fv-xxxx",
"flow_slug": "order-intake"
},
"$node": {
"id": "node-notify",
"label": "Notify customer"
}
} 示例运行所基于的编排器提交 31e874b