Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support wildcard in jsonpath #169

Closed
lepapareil opened this issue Feb 15, 2021 · 1 comment
Closed

Support wildcard in jsonpath #169

lepapareil opened this issue Feb 15, 2021 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@lepapareil
Copy link
Collaborator

lepapareil commented Feb 15, 2021

i create a simple fake api returning a json collection with netcat on port 8080:

$ while true ; do
  {
  echo -e "HTTP/1.1 200 OK\n\n"
  echo '{ "items" : [ { "item" : "a" } , { "item" : "b" } ] }'
  } |  nc -vl 8080 -q 1
done
Listening on [0.0.0.0] (family 0, port 8080)

i first request it with curl and jq to check that the json response is valid:

$ curl --silent http://localhost:8080 | jq -r .items[].item
a
b

i create a test.hurl file with a jsonpath collection assert (validated with external tools):

GET http://localhost:8080

HTTP/1.1 200

[Asserts]
jsonpath "$.items.[*].item" includes "a"

i run hurl

$ hurl --version
hurl 1.1.0

$ hurl test.hurl --verbose
* fail fast: true
* insecure: false
* follow redirect: false
* max redirect: 50
* ------------------------------------------------------------------------------
* executing entry 1
* 
* Cookie store:
* 
* Request
* GET http://localhost:8080
* 
> GET / HTTP/1.1
> Host: localhost:8080
> Accept: */*
> User-Agent: hurl/1.1.0
> 
< HTTP/1.1 200 OK
< 
* Response Time: 43ms
* 
error: Invalid jsonpath
  --> test.hurl:6:10
   |
 6 | jsonpath "$.items.[*].item" includes "a"
   |          ^^^^^^^^^^^^^^^^^^ the jsonpath expression '$.items.[*].item' is not valid
   |

i try with another valid jsonpath such as "$.items.[]item" but got the same error ... something seems to be wrong with the jsonpath parser used in hurl because I get the same error even using your documentation example at https://hurl.dev/docs/asserting-response.html#jsonpath-assert:

error: Invalid jsonpath
  --> hurdev-jsonpath-example.hurl:9:10
   |
 9 | jsonpath "$.slideshow.slides[*].title" includes "Mind Blowing!"
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the jsonpath expression '$.slideshow.slides[*].title' is not valid
   |
@lepapareil lepapareil added the bug Something isn't working label Feb 15, 2021
@fabricereix fabricereix changed the title some jsonpath expressions do not work Support wildcard in jsonpath Feb 15, 2021
@fabricereix
Copy link
Collaborator

fix in #170

@lepapareil lepapareil added this to the 1.2.0 milestone Feb 23, 2021
@lepapareil lepapareil removed the 1.2.0 label Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants