jsonDOMSearch
Version 24.2.9039
Version 24.2.9039
jsonDOMSearch
Loop over the elements in an input JSON document.
Required Parameters
- jsonpath: The 1-based index jsonpath of the specified segment to loop over (for example,
<arc:set attr=”myinputitem.jsonpath” value=”/json/foo/” />
).
Optional Parameters
- 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.
Output Attributes
- 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 thefoo
JSON element, which isfoo
). - type: Returns the data type of the specified element being looped over (for example,
[myoutitem.type]
resolves toSTRING
if thefoo
element has a string value).
Example
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: