Showing results for 
Search instead for 
Did you mean: 

Complex JSONPATH example - extracting values from a deep branch underneath

Former Employee

Here is an example of a very complex json tree and how to extract values from the middle of the tree.

If you look at this sample json, we need to extract the TenderType and AuthorizationCode under the Tender Element and also extract the ab1:BeginDateTime where the @EventName": "First Item Time" under ab1:Event.

You can see immediately that the both the Tender and SequenceNumber are at different levels under the tree.


The following expression will get the authorization code.

> jsonPath($, “$RetailTransaction.LineItem[?(@.hasOwnProperty(‘Tender’) == true)].Tender.Authorization.AuthorizationCode”)

As you can see, LineItem is an array and within the array, instead of [*], @ gets the current node and we are checking if the current node has Tender Element. If the node has Tender element then get the AuthorizationCode under Authorization.

The above is one level nested deep.

The following expression will get the BeginDateTime under ab1:Event where the eventname = ‘First Item Time’

> jsonPath($, “$RetailTransaction.LineItem[?(@.hasOwnProperty(‘ab1:TransactionExtensions’) == true)].[‘ab1:TransactionExtensions’][‘ab1:SpeedOfService’][‘ab1:OrderSpeedOfService’][‘ab1:SOSTransaction’][‘ab1:Event’][?(@[‘ab1:EventID’][‘@EventName’]==‘First Item Time’)][‘ab1:BeginDateTime’]”)

As you can see, in the LineItem array, first find if the element has ‘ab1:TransactionExtensions’ then, go deep unto the ab1:Event array and within that array again first if the eventname equals First Item Time, and then get the element ab1:BeginDateTime

I hope this helps in resolving complex JSON PATH expressions.

Enclosed is the pipeline too that demonstrates and make use of this.

Complex-JsonPath.slp (11.0 KB)