jsonDOMSearch

Version 24.3.9106


jsonDOMSearch


Loop over the elements in an input JSON document.

必要なパラメータ

  • jsonpath: The 1-based index jsonpath of the specified segment to loop over (for example, <arc:set attr=”myinputitem.jsonpath” value=”/json/foo/” />).

オプションのパラメータ

  • uri: A JSON file URI (for example, http://mydomain.com/resources/somedata.json, /tmp/myfile.json or [FilePath]).
  • text: A readable handle reference to the JSON data. This handle is created by the jsonOpen operation and is helpful when the input JSON is not a file or raw text, or when it is necessary to perform multiple actions that access the file data of the document.
  • handle: A readable handle reference to the JSON data. This handle is created by the jsonOpen operation and is only necessary when the target JSON is not an input file. See jsonOpen for details and examples.

アウトプット属性

  • jsonpath: The 1-based index jsonpath(s) of the output item relative to the jsonpath set on the input item.
  • name: Returns the name of the specified element being looped over (for example, [myoutitem.name] resolves to the name of the foo JSON element, which is foo).
  • type: Returns the data type of the specified element being looped over (for example, [myoutitem.type] resolves to STRING if the foo element has a string value).

Consider this JSON passed in as an input file:

{
    "hello": "world",
    "colors": [
        {
            "color": "yellow",
            "example": "banana"
        },
        {
            "color": "red",
            "example": "apple"
        },
        {
            "color": "orange",
            "example": "orange"
        }
    ]
}

You can use the jsonDOMSearch operation to enumerate over all the objects in the colors array, as shown below:

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

The output in the application log looks like this: