cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Complex JSONPATH example - extracting values from a deep branch underneath

nganapathiraju
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.

6189748e8900392f73750638ca0c74f9d7379d64.png

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)

0 REPLIES 0