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

4.0.0 breaks jsonpath with filter #1970

Closed
RELAXccc opened this issue Sep 27, 2023 · 2 comments
Closed

4.0.0 breaks jsonpath with filter #1970

RELAXccc opened this issue Sep 27, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@RELAXccc
Copy link

What is the current bug behavior?

My script that works in hurl version 3.0.1 throws now:
"""
error: Unrenderable variable
--> client_setup/get_clientId.hurl:11:60
|
11 | GET {{url}}/auth/clients/{{client_id}}/client-secret
| ^^^^^^^^^ variable <client_id> with value [THIS_IS_AN_ID] can not be rendered
|
"""

Steps to reproduce

add
"""
[Captures]
client_id: jsonpath "$[?(@.name=='{{my_client}}')].id"
"""
to a step that returns an array with multiple objects that contain id and name

this should return the id of client "my_client" as follows:

THIS_IS_AN_ID

returns as follows:

[THIS_IS_AN_ID]

##maybe a solution

I think the fix for #1469 could have introduced this error.

I can't find any way to make my configurations work with version higher than 4.0.0

@RELAXccc RELAXccc added the bug Something isn't working label Sep 27, 2023
@jcamiel
Copy link
Collaborator

jcamiel commented Sep 27, 2023

Hi @RELAXccc

Starting with Hurl 4.0.0, we've slighty changed JSONPath evaluation to be more correct. When your JSONPath contains a filter (like ?(@.name=='{{my_client}}')), the Hurl queries will return a collection. You can have more details about this change here https://hurl.dev/blog/2023/06/30/announcing-hurl-4.0.0.html#jsonpath-change

In your case, you can extract an item from the collection with nth filter:

....
[Captures]
client_id: jsonpath "$[?(@.name=='{{my_client}}')].id" nth 0

GET {{url}}/auth/clients/{{client_id}}/client-secret

We have done this change to deal with edge cases and to be more consistant with JSONPath spec

@RELAXccc
Copy link
Author

Oh sorry that I did not read these changelogs. thank you a lot for the fast answer, you are helping me a lot rn

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