It is quite easy to evaluate Xpath expression in Iflow and assign them to Property or Header. But there is no direct way of evaluating JSON body and extract information we require. We can write a Groovy script to parse JSON body and extract information required but then we have to write custom script for each payload type. In this blog I'll try to provide generic Groovy script which can be used to extract values from JSON body.
GPath option in Groovy
a.b.c → yields the c properties for all the b properties of a
Now we know GPath expression, but in order to evaluate the expression we will be using groovy.util.Eval class which is available with Groovy. This class is a simple helper on top of GroovyShell. You can use it to evaluate small Groovy scripts that don't need large Binding objects.
Parameters to Groovy script will be passed via properties -
gpath_expr (Required) - Just like Xpath expression we should have input parameter to pass GPath expression. gpath_setproperty (Optional) - Extracted value should be assigned to this property gpath_setheader (Optional) - Extracted value should be assigned to this header
if both gpath_setproperty and gpath_setheader are not defined, the extracted value will be set gpath_result property