> ## 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" />
