postmanlabs / postman-app-support

Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs—faster.
https://www.postman.com
5.81k stars 839 forks source link

? filter query syntax for JSON value check tests #2454

Closed aolson58 closed 7 years ago

aolson58 commented 7 years ago
  1. Postman Version: 4.8.1
  2. App (Chrome app or Mac app): Chrome app
  3. OS details: Windows 10 64-bit
  4. Is the Interceptor on and enabled in the app: no
  5. Did you encounter this recently, or has this bug always been there: n/a
  6. Expected behaviour: when attempting a json data check on a response body, i would expect to be able to use the filter syntax from jsonPath to be able to filter on results for example

example json response

{ "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 10 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 }, { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 } ], "bicycle": { "color": "red", "price": 19.95 } }, "expensive": 10 }

I would expect a test like

tests['test name'] = jsonData.store.book[?(@.price == 10)].title == 'Sayings of the Century' to return me pass but instead postman returns "There was an error in evaluating the test script: Unexpected token ?

Is there some syntax that I am missing or is this not supported

aolson58 commented 7 years ago

I didn't see anything in the documentation supporting this syntax and attempted to exhaust the stack overflow threads as well

sdnts commented 7 years ago

@aolson58 Test scripts in Postman are written in ES5 Javascript. I had a look at JSONPath, and it looks like it is made for Java, so we do not (cannot) support this as of now. You do have access lodash in the test scripts, so you could use that to do your filtering :)

nithril commented 6 years ago

It exists jsonpath libraries for javacript since years: https://github.com/s3u/JSONPath https://github.com/dchester/jsonpath

ykhodos commented 6 years ago

It looks like there is JsonPath for Javascript https://www.npmjs.com/package/jsonpath http://goessner.net/articles/JsonPath What does it take to make it work in Postman?