Text Processor
With the text processor, details are extracted from the random texts which are made available via the input and are then forwarded. In this respect, regular expressions and JSON path definitions are available. In this way, outputs of the http-Request logic element are processed, for example.
Contents
Inputs and outputs
Inputs
GATE (see Logic Elements | Datapoint-Gate)
IN
Input for the text for processing
Outputs
OUT 1 ...
Up to 20 outputs which provide the result of either a JSON path or a regular expression.
Configuration
The evaluation of the text elements occurs via the configuration dialog, which is available in the parameters via the gears icon in the “outputs” field. Here, the different filtered elements can be forwarded on the corresponding outputs.
In the upper part of the configuration you have the option of selecting the text type and saving an example text in order to test the evaluations provided below.
Text type
A selection of several text types is available:
Plain Text (text/plain)
JSON (application/json)
XML (text/xml)
HTML (text/html)
The selection of the text type influences the possible selection with “selector” in the table for the output configuration below and is also a source of help. In this context, with the “JSON” text type selection, it may be possible to enter JSON paths there. The selection of the text type has no effect on the actual function.
Output configuration
There is one line per output with which the requested elements can be filtered from the text via the corresponding samples/paths. It is possible to see the appropriate results on the stated text in the right-hand column. The example illustrates an output of Openweathermap which is available in the JSON format. Every output is assigned a /wiki/spaces/LEHC/pages/28050253 which is transformed into the found value. If the output in the selected data type is not possible, then no data is issued. If no result is determined for an output, then no data is issued either.
Setting of a JSON path
JSON only recognises objects and arrays for the structuring. Objects address their characteristics through keys and are defined by curly brackets (" { } "). Arrays are a juxtaposition of values and are determined by square brackets (" [ ] "). Possible values:
Boolean values (true / false)
Numbers
Character strings (text in double quotes)
Arrays (can contain values of any type)
Objects (can contain values of any type)
Example:
{
"coord": {
"lon": -0.13,
"lat": 51.51
},
"weather": [
{
"id": 300,
"main": "Drizzle",
"description": "light intensity drizzle",
"icon": "09d"
}
],
"base": "stations",
"main": {
"temp": 280.32,
"pressure": 1012,
"humidity": 81,
"temp_min": 279.15,
"temp_max": 281.15
},
"visibility": 10000,
"wind": {
"speed": 4.1,
"deg": 80
},
"clouds": {
"all": 90
},
"dt": 1485789600,
"sys": {
"type": 1,
"id": 5091,
"message": 0.0103,
"country": "GB",
"sunrise": 1485762037,
"sunset": 1485794875
},
"id": 2643743,
"name": "London",
"cod": 200
}
Possible paths:
"weather[0].id" results in "300"
"clouds.all" results in "90"
"name" results in "London"
It is also possible, for example, to start a JSON path with an Array index ("[2]") if the JSON which is provided is structured accordingly.
If you enter the text for the output data type, JSON structures can also be issued as a result. In the aforementioned example, the path “clouds” results in {“all”: 90}
Setting of a regular expression
With regular expressions it is possible to search for and extract almost any text in requested areas.
Not all web services provide their results in the form of easy-to-process JSON.
Example:
LightNo=1
LightState=1
RED=255
GREEN=255
BLUE=255
LightNo=2
LightState=0
RED=255
GREEN=0
BLUE=0
If, for example, you would like to know the status of the lamp with the ID 2, the following expressions would be required:
General switch status
LightNo=2[\s\S]*?LightState=([01])
with the result 0Red channel
LightNo=2[\s\S]*?RED=(\d+)
with the result 255Green channel
LightNo=2[\s\S]*?Green=(\d+)
with the result 0Blue channel
LightNo=2[\s\S]*?BLUE=(\d+)
with the result 0
Via LightNo=2
you define the start of the search. Part [\s\S]*? states that more-or-less any character ("white space" and "non-white space" values) can be used in any quantity. The last part defines the specific value to be searched for. In the case of the general status
LightState=([01])
. The part which is described in the curly brackets is that which is to be issued at the end. The part described in square brackets [01] provides the possible values which can be interpreted as valid. With the coloured values, it is only the \d+, which shows that it is one number or more.
A good source of help for the testing of regular expressions is the following page https://regex101.com/. The reference there is a good source of support, and it is possible to test and improve the regular expressions here.
If several expressions are connected via ("|") or several search groups are defined, only the first value to be found is issued. Please only use one individual regular expression per searched value.