JSON Finders
A JSON Finder is used to find necessary data in a JSON text. The list of Finders of the current step is located in the Step View, Finders tab.
For more information about JSON and its terminology see Working with JSON.
JSON Finder Properties
A JSON Finder can be configured using the following properties.
- Find Where
- In this property, you can specify where to find a JSON element. The default value is "Anywhere in JSON", meaning that named JSONs are not used in a search.
- In this named JSON
- This property is used when you select In Named JSON in the Find Where list. In this property, you can specify whether to search in the selected Named JSON or you can specify a name of the Named JSON to use.
- Path
- In this property, you can specify the path to the JSON element. The tag path can be specified in several ways using
the
Value Selector.
JSON path expressions always refer to a JSON structure in the same way as XPath expression are used in combination with an XML document. JSON path expressions are very similar to the JavaScript and use the dot-notation, for example personnel.person[0].name. @top: element is required and tells the finder to search from the top of the JSON.
- Examples
-
- JSON Path
-
The following is a simple JSON structure and a table with path examples and possible results.
{ "personnel" : { "person" : [ { "ID" : 0, "name" : "Bob", "age" : 26, "isMale" : true }, { "ID" : 1, "name" : "Ted", "age" : 25, "isMale" : true }, { "ID" : 2, "name" : "Jill", "age" : 47, "exam" : "553213-3", "isMale" : true }, { "ID" : 3, "name" : "Rick", "age" : 50, "exam" : "553225-3", "isMale" : true } ] } }
XPath
JSON Path
Result
/personnel/person[2]/name
@top:.personnel.person[1].name
Ted
/personnel
@top:.personnel
Extracts all information from "personnel"
A new finder with square brackets is used if your JSON name contains any of the following characters:
. " .. [ ] \
For example, if your JSON name contains a dot in its name, such as { "main.key": 42 } and you insert the Extract JSON step by right-clicking an element in the Applications pane, the step automatically inserts the following finder:
@top:["main.key"]
Both syntaxes are interchangeable and all previously created JSON finders will work in a newer version of RPA.
If you want to extract a set of information from a JSON element, you can create an XML page from JSON and extract necessary information using a text expression. For example, if you create an XML page from the JSON above, select item[1] in the XML, and run an expression like ".*<name>"+TheInput+"</name>.*", as a result you should get something similar to 1Ted25true.
- Finding a Named JSON
-
In the following example Named JSON is a part of a JSON text that can be used in a JSON Finder to find "a":
In the following JSON text:
{ "a" : [{ "b" : [1,2,3] }], "c" :42 }
we can have the Named JSON mark
"b" : [1,2,3]
and thus we can have a JSON Finder perform a search with the following properties:
Find Where: In Named JSON
In this Named JSON: 1
Path: [1]
This finder will then find the number 2 in the list.