Formula - Extract

jsonpath

jsonpath('Expression',body) , this function implemented JSONPath functionality, jsonpath function used to navigate into a specific element within JSON body structure.

Syntax

On the Message Body :

jsonpath('Expression ',body)

On the Message Context :

jsonpath('Expression',context('MessageContextKey'))

Some operations on the Message Body :

1.Simple jsonpath content parameter

Example: if the body content is JSON  structure with one element called "Seq" that is equal "2" and 'Seq' is the Expression, the result will be "2".

Test Expression

e.g. jsonpath('Seq',body)

JsonPath_simpleParameter


2.Simple JSON(Array) content parameter

Example: The body content is JSON  array contains multiple Id's ,JsonPath function will return a list of id's in the same order, where the given expression(Valid JSONPath syntax) is ($..Id) . 

Test Expressiosn

e.g. jsonpath('$..Id',body)

JsonPath_multiple_body

Some operations on the Message Context :

1.Simple jsonpath content parameter

Example:The Message context value is JSON structure with one element called "Seq"  and the key is "id" , the return result will be "2" which is the value of "Seq" within JSON body. 	

Test Expression

e.g. jsonpath('Seq',context('id'))

JsonPath_simpleParameter_MessageContext


2.Nested regex( ) as content parameter (Multiple Keys).

Example: The Message Context value is JSON array contains multiple Id's each one of these values corresponding a certain Message Context key , here we are applying regex function on key field and return a list of JSON elements values by using valid JSONPath syntax expression.  

Test Expression

e.g. jsonpath('$..Id',context(regex('id.*')))

JsonPath_messageContext_multiples


xpath

xpath('Expression',body) , this function used to navigate over nodes in any XML structure. Simply its implemented XPath as its elsewhere with more advance features added by Formula Plugin specification.

Syntax

On the Message Body :

xpath('Expression ',body)

On the Message Context :

xpath('Expression',context('MessageContextKey'))

Some operations on the Message Body :

  1. Simple xpath content parameter

    Example: If the body content is simple XML structure(One Element) and the expression parameter is "/Id" , the result will be "3" which is the node value.

Test Expression

e.g. xpath('/Id',body)

xpath_simpleParameter


2.simple xpath content parameter (Multiple Xpath nodes)

	Example: The body content is XML structure and the expression parameter is "Orders/Id" , the result will be "3" and "6".  

Test Expression

e.g. xpath('/Orders/Id', body)

xpathNodes_multiple_body


3.Nested base64decode() as content parameter

	Example: The body content is base64encode XML structure and the expression parameter is "Orders/Id" , the result will be "3" and "6" where the content parameter is base64decode function (Formula Specification).  

Test Expression

e.g. xpath('/Orders/Id',base64decode(body))

xpathNodes_multiple_body_nestingFunction

Some operations on the Message Context :

1.Simple xpath content parameter

Example:The Message context value is XML with one node and the key is "id" , the return result will be "3" which is the value of given node. 	

Test Expression

e.g. xpath('/Id',context('id'))

xpath_simpleParameter_MessageContext


2.Nested regex( ) as content parameter

Example: The Message Context value is XML(one parent node with two children), we applied regex function on Key field to get multiple values and return XML nodes values through xpath function as result. 

Test Expression

e.g. jsonpath('$..Id',context(regex('id.*')))

Xpath_messageContext_nestedFunction


regex

Implemented Regular Expression as it is implemented everywhere. In other words, as long as the first parameter of the regex('Expression','Content') is a valid Regular Expression the function will return the matched result.

Syntax

On the Message Body

regex('Expression',body)

On the Message Context

regex('Expression',context('id'))

Some operations on the Message Body :

1.Simple regex content parameter

Example: If the body content is "This is number 5 "and the expression parameter is "\d+" which is a valid Regular Expression , the result will be "5".  

Test Expression

e.g. regex('\d+',body)

regex_simpleParameter


Some operations on the Message Context :

1.Simple regex content parameter

Example:The Message context value is normal text "GMT"  and the key is "id" , the return result will be "GMT". 	

Test Expression

e.g. regex('GMT|UTC',context('id'))

regex_MessageContext


2.Nested regex() as content parameter

Example: The Message Context value is normal text, we applied regex function on Key field to get multiple values and return list of matches. 

Test Expression

e.g. regex('GMT|UTC',context(regex('id.*')))

regex_messageContext_nestedFunction


csv

csv('SkippedHeaderRow','Delimiter','ColumnIndex','CommentSymbol',Content) ,it is extremely powerful and flexible function used to read CSV file structure , this function accepts five parameters as stated above:

  • SkippedHeaderRow: Specify how many row to skip in the beginning of the file, when reading the csv. This can be actual header rows or just i like to skip the first 5 rows.
  • delimiter: used to separate the csv data item.
  • ColumnIndex: Used to read a certain column of the csv.
  • CommentSymbol: Used to assign a certain row as comment row.
  • Content:its the file content itself.

Syntax

On the Message Body

csv('SkippedHeaderRow','Delimiter','ColumnIndex','CommentSymbol',body)

On the Message Context

csv('SkippedHeaderRow','Delimiter','ColumnIndex','CommentSymbol',context('id'))

Some operations on the Message Body :

1.Simple csv content parameter

Example: The body content is normal csv content with a comma delimiter',' as its specify in the 2nd parameter ,start reading from row number "3" since the skippedHeaderRow value is "2", ready column number "1"(Zero based column index) and use "#" as a comment symbol.
Notice: Row number "4" skipped because its a comment row starts with "#".

Test Expression

e.g. csv(2,',',1,'#',body)

csv_simpleParameter


2.Nested jsonpath( ) as content parameter

Example:The body content is json structure contains csv content, we are using jsonpath() in order to navigate into "list" element thats contain csv data items and read that csv. 

Test Expression

e.g. csv(4 ,',',1,'#',jsonpath('$.content',body))

csv_nestedJsonpath

Some operations on the Message Context :

1.Simple csv content parameter

Example:The Message context value is normal csv content ,with semicolon ";" delimiter where the key is "id".

Test Expression

e.g. csv(4,';',1,'#',context('id'))

csv_MessageContext


2.Nested jsonpath() as content parameter

Example: The Message Context value is JSON structure contain a csv, notice that we apply regex( ) on the key field in order to get multiple values and then read them with csv function and return common list result

Test Expression

e.g. csv(3,',', 1,'#', jsonpath('$.content',context(regex('id.*'))))

csv_nestedjson_regex


substring

substring(startIndex,length,Content) ,this formula function is used to extract specific text(Substring) from any given text based on the start index and the length parameter. In other word , it works just like any substring function in any programming language(Mostly).

Syntax

On the Message Body :

substring(startIndex,length,body)

On the Message Context :

substring(startIndex,length,context('MessageContextKey'))

Some operations on the Message Body:

1.Simple substring Content parameter

Example: if "nodinite" is the body content.The result will be "nodi" where the startIndex is "0" and the length is "4". 	

Test Expression

e.g. substring(0,4,body)

Simple Content parameter_substring


2.Nested jsonpath() as Content parameter

Example: The body content is an array of json (Or any json structure) and the Content parameter is jsonpath function(Formula specification) , the substring function rules will apply for all selected elements by jsonpath function. 

Test Expression

e.g. substring(0,2,jsonpath('$..name',body))

nested Content parameter_substring


Some operations on the Message Context :

1.Simple substring Content parameter

Example: if "Amazing Function" is the Message Context value and the key is "id".The result will be "Amazing" where the startIndex is "0" and the length is "7". 

Notice: if the length is "8" visually we will get the same result "Amazing " because substring counts the white spaces.

Test Expression

e.g. substring(0,7,context('id'))

Simple Content parameter_substring


2.Nested jsonpath() as Content parameter

Example: if body content is json (Or array of json) and the Content parameter is jsonpath function(Formula specification) , the substring function rules will apply for all selected nodes with jsonpath function.

Notice here we are applying regex function (Formula specification) on the Message Context key field instead of a certain key such as  context('id') in order to select multiple keys and apply the substring function.

Test Expression

e.g. substring(0,2,jsonpath('$.name',context(regex('id.*'))))

nested Content parameter_substring


replace

replace(oldText,newText,Content) , used to replace a specific char with a another char(It Works with String as well), the result will contains the newText instead of oldText.

Syntax

On the Message Body :

replace(oldText,newText,body)

On the Message Context :

replace(oldText,newText,context('MessageContextKey'))

Some operations on the Message Body:

1.Simple replace Content parameter

Example: if "nodinite" is the body content.The result will be "The worlds most innovative product" where the oldText is "nodinite" and the newText is "The worlds most innovative product". 	

Test Expression

e.g. replace('nodinite','The worlds most innovative product',body)

Simple Content parameter_replace


2.Nested jsonpath() as Content parameter

Example: If body content is an array of json (Or any json structure) and the Content parameter is jsonpath function(Formula specification) , the replace function rules will apply for all selected nodes with jsonpath function. 

Test Expression

e.g. replace('Amazing','Cool',jsonpath('$..name',body))

nested Content parameter_replace


Some operations on the Message Context :

1.Simple replace Content parameter

Example: Assume "nodinite" is the Message Context value and the key is "id".The result will be "The worlds most innovative company" where the oldText is "nodinite" and the newText is "The worlds most innovative company". 

Test Expression

e.g. replace('nodinite','The worlds most innovative company',context('id'))

Simple Content parameter_replace


2.Nested jsonpath( ) as Content parameter

Example: Body content is json and the content parameter is jsonpath function(Formula specification) , the replace function rules will apply for all selected nodes with jsonpath function.

Notice here we have applied regex function (Formula specification) on the Message Context key field instead of a certain key such as  context('id') in order to select multiple keys and apply the replace function.

Test Expression

e.g. replace('Amazing','Super',jsonpath('$.name',context(regex('id.*'))))

nested Content parameter_replace