Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

JSONpath Expression for GET call #66

Closed
sadams3180 opened this Issue Jul 30, 2013 · 4 comments

Comments

Projects
None yet
3 participants

Hi Fabrizo,

The following JSONpath expression works in a GET call in Fitnesse.
Fitnesse:
| GET ||||jsonbody.albums.title=="Black"|

JSON:
{"name":"Metallica","albums":[{"year":"1991","title":"Black","tracks":["1:Enter Sandman","2:Holier Then Thou","3:The Unforgiven"]}]}

My question is this. Is there a similar JSONpath expression that can be used in a GET call to see if an object contains a character(s) rather than an entire value?
For example rather then jsonbody.albums.title=="Black" I would use something like jsonbody.albums.title=="Bla".

Does such an expression exist for Restfixture in a GET call?
Thanks,
-Sam

Owner

smartrics commented Aug 1, 2013

you can use any javascript expression in the cell, provided that the last expression returns a boolean
check the livedocs for examples

@smartrics smartrics closed this Aug 1, 2013

Thanks Fabrizo, you happen to have an example of a contain expression that would work with Restfixture/Fitnesse? Ones I tried didn't work unfortunutly.
Example of ones not working:
| GET |||| jsonbody.albums.[?(@.title:contains(Bla))] |
Or
| GET |||| $.[?(@.albums.title:contains(Bla))] |

I'm probably missing something. Any help is appreciated.

Owner

smartrics commented Aug 1, 2013

any javascript tutorial would tell you how to manipulate strings
for example
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf

jsonbody.albums[0].title.indexOf("Bla") >=0

should do

Hi,

What if you want to check album which title is "Black" was published on year 1991 (suppose there are several albums for Metallica) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment