Answered

GET_REST_VALUE Keys JSON Path with functions

Is there a way to do filtering in Keys/Xpaths fields?

For example:

store.book[?(@.category == 'reference')

OR

store.book[?(@.price >= 9.00)

 

{

"store": {

"book": [

{

"category": "reference",

"author": "Nigel Rees",

"title": "Sayings of the Century",

"price": 8.95

},

{

"category": "fiction",

"author": "Evelyn Waugh",

"title": "Sword of Honour",

"price": 12.99

},
"category": "fiction",

"author": "J. R. R. Tolkien",

"title": "The Lord of the Rings",

"isbn": "0-395-19395-8",

"price": 22.99

}

]
}

0
18 comments
Avatar
Dominic Luminello

Hi Joseph,

 

I am actually interested in filtering the Keys/Xpaths within the Get_Rest_Value command itself, not searching/filtering for steps in Subject7.

See screenshot.

0
Comment actions Permalink
Avatar
Dominic Luminello

I was able to get 'filtering' to work as you shared above but there seems to be an issue whenever more than 1 node/object is returned.

I noticed that if the filter returns only 1 node it will store the value appropriately in the variable defined however if it returns 2 or more nodes Subject7 sets the variable = null.  I would expect the variable to be set to an array of values that I could then iterate through.

0
Comment actions Permalink
Avatar
Dominic Luminello

Any updates on this?

0
Comment actions Permalink
Avatar
Joseph Hamdan

Hi Dominic,

We are still looking at this issue, an update will be sent as soon as possible.

Thank you so much for your patience.

Regards,
Subject7 Team

0
Comment actions Permalink
Avatar
Dominic Luminello

Hi,

I am really struggling with retrieving/getting what I need back from a REST call and being able to do something with it.

Can we please have a call where I can share my issues?

0
Comment actions Permalink
Avatar
Joseph Hamdan

Hi Dominic,

Apologies for the delay as this is still under investigation.

Apart from the issue reported earlier, are you experiencing any other issues?

Regards,
Subject7 Team

0
Comment actions Permalink
Avatar
Dominic Luminello

They are all somewhat related to this issue but yes, I am having other issues.  If I try to get a count (JSON_COUNT) on an array object in JSON it doesn't return a count.  This is similar to the issue above.  Here is a snippet of the JSON return by the REST request.

I am trying to get the count on airmetList under fzlvl with the below values but nothing is returning anything:

ngbweatherBriefing.fzlvl.airmetList[*]

ngbweatherBriefing.fzlvl.airmetList

 

 

Was also looking for way to see if one of those array items contains a specific value which doesn't work either.

All seems to be related to the issue above where if multiple items are return (an array) Subject7 sets it to null.

ngbweatherBriefing.fzlvl.airmetList[*].text[?(@.encodedText contains "PSK-30S")]

 

0
Comment actions Permalink
Avatar
Rex Feizi

The term "filtering" doesn't quite apply here. Subject7 commands work in a request/response fashion. We don't keep a stream open on any commands so far. So when you make a REST call, you get the response and that's it. You can validate the response to see if it matches certain criteria, whereas filtering means you keep the data and then you start the operations on it, which is not the case here. 

In short, you can make a REST call to get a response and save it as a variable. For example, use "/bookstore/book[price>35]/price" XPath to store the count in a variable, then use compare to do whatever you need to do. 

Hope this helps. 

0
Comment actions Permalink
Avatar
Dominic Luminello

Understood, however that last paragraph/sentence does not work.

In the example you gave, if I use use "/bookstore/book[price>35]/price" and there is only one book that is greater than 35, then it works fine and returns the value/price for that one book.  If it results in 2 or more books that are greater than 35, it returns null.  I would expect to get back an array of prices to iterate through.

0
Comment actions Permalink
Avatar
Dominic Luminello

Ultimately what I am trying to do is find a JSON node with property 'x' that contains a value, say 'abc123' and then retrieve that nodes property 'y' and verify that it equals null.

0
Comment actions Permalink
Avatar
Jonathan Hotz

Hi Dominic.

Thanks again for your JSON, so we could test possible solutions.

You can use next commands to do required comparison:

1. Get_Rest_Value command with next JSON Path:

ngbweatherBriefing.fzlvl.airmetList[?(@.text.encodedText contains 'PSK-30S' && @.geometry==null)].text.encodedText

2. Compare or If commands, where you should compare result of command from point #1 with @System.null.

 

Explanation

Our REST commands operate with simple types only as final output: strings, numbers, null, etc. It doesn't operate with JSON nodes as final result.

If you provide path like below, Get_Rest_Value command will fail:

ngbweatherBriefing.fzlvl.airmetList[?(@.text.encodedText contains 'PSK-30S' && @.geometry==null)]

That's why we are looking for a field of target object (.text.encodedText as example).

If object with given text and (geometry == null) doesn't exist result value of Get_Rest_Value will be null.

If target object exists we will get required element value (encodedText).

Then we can use received value in comparison commands.

 

Additional Info

I found that ngbweatherBriefing.icing also contains 'PSK-30S' inside encodedText value. In such case you need JSON Path with negotiation:

ngbweatherBriefing.icing.airmetList[?(@.text.encodedText contains 'PSK-30S' && @.geometry!=null)].text.encodedText
0
Comment actions Permalink
Avatar
Dominic Luminello

Thank you Alexei!

I verified the above JSON Key/Path does work and returns the encodedText that I can then use the Contains command to check values in it.

I tried the same for Verify_REST and it seems there is an issue there.

I used the same ngbweatherBriefing.fzlvl.airmetList[?(@.text.encodedText contains 'PSK-30S' && @.geometry==null)].text.encodedText

And entered 'PSK-30S' for the value and then chose 'CONTAINS'.  

When I either run this step OR just refresh the test, it seems Subject7 reparses the values and changes them.

Subject7 changes the Field key field to be 'ngbweatherBriefing.fzlvl.airmetList[?(@.text.encodedText contains 'PSK-30S' && @.geometry' 

The Field value to be '=null)].text.encodedText{PSK-30S' and the Operator to be 'EQUALS'.

See below screenshots.

 

 

0
Comment actions Permalink
Avatar
Joseph Hamdan

Hi Dominic,

Thank you so much for reporting this issue in detail, we greatly appreciate it. An internal request has been created to fix it.

Have a wonderful day!

Regards,
Subject7 Team

0
Comment actions Permalink
Avatar
Dominic Luminello

Thank you Joseph.

Another question I have is how would I do NOT CONTAINS?

For example below:

ngbweatherBriefing.ifr.airmetList[?(@.text.encodedText NOT contains 'OTLK VALID')].isOutlook

0
Comment actions Permalink
Avatar
Jonathan Hotz

Hi Dominic.

You should wrap your condition expression with negotiation. For encodedText you can use next:

ngbweatherBriefing.ifr.airmetList[?(!(@.text.encodedText contains 'OTLK VALID'))].text.encodedText

isOutlook is not good choice for such case. As I saw in the JSON you had sent isOutlook for ifr is null.

So if there is an element that fits condition you will get null, because isOutlook value is null If there is no any element that fits condition you will get null too as described in my previous comment.

In such case there is nothing to compare, so I suggest to use fields that will not be null.

0
Comment actions Permalink
Avatar
Dominic Luminello

Understood, thank you Alexei.

We have different versions of the same REST api (for different vendors) so the responses I am getting back currently have 'true' or 'false' for the isOutlook value (different version than what I sent you).  If encodedText contains 'OTLK VALID' then isOutlook should always be equal to 'true' and if it doesn't contain 'OTLK VALID' then isOutlook should be 'false'.

0
Comment actions Permalink

Please sign in to leave a comment.