> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kasoftware.com/llms.txt
> Use this file to discover all available pages before exploring further.

# jsonDOMSearch

> 在输入 JSON 文档中循环处理元素，并使用 jsonpath 枚举重复结构。

循环输入 JSON 文档中的元素。

## 必需的参数

* **jsonpath**: 要循环的指定段的从 1 开始的索引 jsonpath（例如，`<arc:set attr="myinputitem.jsonpath" value="/json/foo/" />`）。

## 可选的参数

* **uri**: JSON 文件 URI（例如 `http://mydomain.com/resources/somedata.json` 、`/tmp/myfile.json` 或 `[FilePath]` ）。
* **text**：对 JSON 数据的可读句柄引用。 此句柄由 [jsonOpen](./op-json-open) 操作创建，当输入 JSON 不是文件或原始文本，或者需要执行访问文档的文件数据的多个操作时，此句柄非常有用。
* **handle**：对 JSON 数据的可读句柄引用。 该句柄由 jsonOpen 运算器创建，仅当目标 JSON 不是输入文件时才需要。 有关详细信息和示例，请参阅 [jsonOpen](./op-json-open)。

## 输出属性

* **jsonpath**：输出项相对于输入项上设置的 jsonpath 的从 1 开始的索引 jsonpath。
* **name**：返回正在循环的指定元素的名称（例如，`[myoutitem.name]` 解析为 `foo` JSON 元素的名称，即 `foo` ）。
* **type**：返回正在循环的指定元素的数据类型（例如，如果 `foo` 元素具有字符串值，则 `[myoutitem.type]` 解析为 `STRING` ）。

## 示例

考虑以下的 JSON 数据作为输入数据：

```json theme={null}
{
    "hello": "world",
    "colors": [
        {
            "color": "yellow",
            "example": "banana"
        },
        {
            "color": "red",
            "example": "apple"
        },
        {
            "color": "orange",
            "example": "orange"
        }
    ]
}
```

可以使用 jsonDOMSearch 运算器来枚举 `colors` 数组中的所有对象，如下所示：

```xml theme={null}
<!-- Setting the input uri and jsonpath -->
<arc:set attr="json.uri" value="[FilePath]" />
<arc:set attr="json.jsonpath" value="/json/colors/" />

<!-- Calling the operation, passing in the json item and creating a "result" output item --> 
<arc:call op="jsonDOMSearch" in="json" >
  <!-- Inside the call you can reference elements at paths relative to the input "jsonpath" -->
  <!-- In this example each color and example from each object inside the "colors" array is logged -->
  <arc:set attr="_log.info" value="Color = [jsonpath(color)]" />
  <arc:set attr="_log.info" value="Example = [jsonpath(example)]" />
</arc:call>

<!-- Setting the output file and pushing the file out -->
<arc:set attr="output.filepath" value="[FilePath]" />
<arc:push item="output" />
```

应用程序日志中的输出如下所示：

<img src="https://mintcdn.com/qiao/bVtjD3fvHFZBo1vE/public/images/jsonDOMSearch.png?fit=max&auto=format&n=bVtjD3fvHFZBo1vE&q=85&s=ad513378142485d723ebd18f73483e98" width="600" data-path="public/images/jsonDOMSearch.png" />
