-
Notifications
You must be signed in to change notification settings - Fork 503
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
Using jsonpath filter on object variable fails #3369
Comments
Hi @luke-pp It sounds reasonable, don't know if it's easy to implement @fabricereix but the features seems "natural" and user can expect it to work. |
Hello, |
Just changed it from "bug" to "enhancement" |
Alternatively, is there a way to "stringify" a variable prior to using jsonpath (or xpath) until this is supported? |
Hi @patkujawa-wf we have the notion of filters like toDate and toInt but we don't have a toString. I'll create an issue to add it, as it seems natural to support it. |
In my company's GraphQL APIs, we can get back some deeply nested json responses with a lot of data, and often we want to perform many different assertions against various parts of the response - ideally we'd like to organize these assertions by capturing one part of the response, and then performing assertions on each captured subsection separately. Here's a simplified example using the star wars API to show what I mean:
In this example, we want to do a couple of assertions about each planet, so we first capture the json objects for Bespin and Tatooine, and then perform assertions against these objects using the jsonpath filter. We could get the same behaviour by just using jsonpath assertions along the lines of
but you can imagine it gets a bit more frustrating in a real workflow outside of the star wars API example.
What is the current bug behavior?
I get errors in the console:
Steps to reproduce
Run the hurl file above
What is the expected correct behavior?
Ideally, the jsonpath should work on the variable object in the same way it works on a full response body/string such that the assertions in the example file pass.
Execution context
I don't think it's particularly relevant to this issue, but
hurl --version
):hurl 4.3.0 (Windows) libcurl/8.4.0-DEV Schannel zlib/1.3 nghttp2/1.58.0
Features (libcurl): alt-svc AsynchDNS HSTS HTTP2 IPv6 Largefile libz NTLM SPNEGO SSL SSPI Unicode UnixSockets
Features (built-in): brotli
Possible fixes
I believe the issue is here:
hurl/packages/hurl/src/runner/filter/jsonpath.rs
Line 33 in 9cfc5b9
The jsonpath filter runner currently only accepts string values, and assumes it needs to parse the string into a json value before evaluating the json path. In our example, the first jsonpath evaluates to fetch the full planet object and capture it to a variable as an object which works fine. But then when we try to use the jsonpath filter on the object to perform assertions against specific items in it, it fails because it is an object rather than a string. I think if we had a second match clause that let us pass through objects (possibly also arrays?) it would help eg:
The text was updated successfully, but these errors were encountered: