# Input Data

> 到达当前节点的数据。

Source: https://docs.sommatic.ai/zh/expressions/reference/input-data/

每个示例都在已部署的表达式引擎上、基于页面末尾的[示例上下文](#example-context)运行过。

## `$json`

变量 · `object` · 来源: `Sommatic AI expression engine`

```javascript
$json
```

路由到当前节点的那个节点的输出。对于触发器之后的第一个节点，它就是触发器交付的内容：webhook 触发器以 `{ body, headers, query, method }` 的形式交付请求。多个分支汇入同一节点时，`$json` 是最后到达的分支的输出；要合并分支，请使用 [`flow.join`](/zh/nodes/flow.join/) 节点。

`$json` 随节点而变。要读取更靠前的节点的数据，请使用 [`$('Node label')`](/zh/expressions/reference/node-reference/#node-accessor)。

### 示例

```javascript
{{ $json.body.email }}
```

结果 (string):

```json
"ana.perez@example.com"
```

```javascript
{{ $json.body.items.length }}
```

结果 (number):

```json
3
```

```javascript
{{ $json.headers['content-type'] }}
```

结果 (string):

```json
"application/json"
```

可能缺失的字段：可选链返回 undefined，而不是报错。

```javascript
{{ $json.body.customer?.phone }}
```

结果 (undefined):

```json
undefined
```

### 错误

- `Cannot read properties of undefined (reading '<field>')`: 路径中的某一级不存在，例如缺少 `phone` 时读取 `$json.body.customer.phone.number`。请使用可选链（`?.`）或 `$ifEmpty`。

在 JSONata 中: `$$json.body.email`. 也可以直接写字段名：JSONata 将输入作为其上下文（body.email）。

## `$binary`

变量 · `object` · 保留 · 来源: `Sommatic AI expression engine`

> **保留.** 引擎尚未填充它：目前始终为 `{}`。不要基于它编写逻辑。

```javascript
$binary
```

用于存放附加到当前条目的文件，每个文件一个键，形式为 `{ data, mimeType, fileName }`。引擎目前尚未填充它：它始终是空对象。如今处理文件的节点会在自己的输出中返回文件，因此请从 `$json` 读取文件（例如电子邮件触发器的附件），或用 `$('…')` 从生成文件的节点读取。

### 示例

```javascript
{{ $binary }}
```

结果 (object):

```json
{}
```

```javascript
{{ Object.keys($binary).length }}
```

结果 (number):

```json
0
```

在 JSONata 中: `$$binary`

## `$itemIndex`

变量 · `number` · 保留 · 来源: `Sommatic AI expression engine`

> **保留.** 节点的每次执行只处理一个条目：目前始终为 `0`。

```javascript
$itemIndex
```

用于表示节点处理批次时当前条目从零开始的位置。一个节点每次执行只处理一个条目，因此它始终为 `0`。要使用列表中某个元素的位置，请使用 `map`、`forEach` 或 `findIndex` 提供的索引，或用 `flow.split` 逐项遍历。

### 示例

```javascript
{{ $itemIndex }}
```

结果 (number):

```json
0
```

列表中每个元素的位置。

```javascript
{{ $json.body.items.map((item, index) => index + ': ' + item.sku) }}
```

结果 (list):

```json
[
  "0: A-100",
  "1: B-200",
  "2: C-300"
]
```

在 JSONata 中: `$$itemIndex`

## `$runIndex`

变量 · `number` · 保留 · 来源: `Sommatic AI expression engine`

> **保留.** 尝试序号不会传给表达式：目前始终为 `0`，重试时也是如此。

```javascript
$runIndex
```

用于统计当前节点的尝试次数（首次为 0，第一次重试为 1……）。引擎不会把尝试序号传给表达式：每次尝试都为 `0`，重试也不例外。重试行为在每个节点的 `execution` 设置中配置（`retryOnFail`、`maxTries`）。

### 示例

```javascript
{{ $runIndex }}
```

结果 (number):

```json
0
```

在 JSONata 中: `$$runIndex`

## 示例上下文

示例基于以下数据运行：当前节点的输入（`$json`）、已运行的节点（`$(…)`）、本次运行的 ID 以及当前节点。时钟固定为 `2026-11-26T14:30:00.000Z`，服务器时区为 UTC，因此各页面中 `$now` 与 `$today` 的值都相同。

```json
{
  "$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"
  },
  "nodes": {
    "Webhook Receiver": "= $json",
    "Normalize input": {
      "correlation_id": "c-7f3a",
      "channel": "web"
    },
    "Classify": {
      "label": "billing",
      "confidence": 0.92
    }
  },
  "run": {
    "$flow_instance_result_id": "fir-xxxx",
    "$flow_instance_id": "fi-xxxx",
    "$flow_definition_id": "fd-xxxx",
    "$flow_version_id": "fv-xxxx",
    "$flow_slug": "order-intake"
  },
  "node": {
    "node_id": "node-notify",
    "label": "Notify customer"
  }
}
```

串联工作流的示例基于第二个上下文运行：一个由 `workflow.chain` 启动的工作流，其 `workflow.trigger` 节点的标签为 `Chain Entry Point`。

```json
{
  "$json": {
    "order_id": "ord_1042",
    "customer_email": "ana.perez@example.com",
    "amount": 46,
    "chain_context": {
      "caller_flow_definition_id": "fd-caller-xxxx",
      "caller_flow_instance_id": "fi-caller-xxxx",
      "caller_flow_slug": "order-intake",
      "caller_node_id": "node-chain-billing",
      "correlation_id": "chain-7Hq2Lw9sKd3pXa1mZr4t",
      "root_flow_instance_result_id": "fir-root-xxxx"
    }
  },
  "run": {
    "$flow_instance_result_id": "fir-hop-xxxx",
    "$flow_instance_id": "fi-hop-xxxx",
    "$flow_definition_id": "fd-billing-xxxx",
    "$flow_version_id": "fv-billing-xxxx",
    "$flow_slug": "billing-review",
    "$input": {
      "data": {
        "order_id": "ord_1042",
        "customer_email": "ana.perez@example.com",
        "amount": 46
      },
      "chain_context": {
        "caller_flow_definition_id": "fd-caller-xxxx",
        "caller_flow_instance_id": "fi-caller-xxxx",
        "caller_flow_slug": "order-intake",
        "caller_node_id": "node-chain-billing",
        "correlation_id": "chain-7Hq2Lw9sKd3pXa1mZr4t",
        "root_flow_instance_result_id": "fir-root-xxxx"
      }
    }
  },
  "node": {
    "node_id": "node-create-task",
    "label": "Create review task"
  }
}
```

示例运行所基于的编排器提交 31e874b.
