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

Invalid JSONPath when using != (not equal) operator #3261

Open
quantonganh opened this issue Sep 26, 2024 · 2 comments · May be fixed by #3281
Open

Invalid JSONPath when using != (not equal) operator #3261

quantonganh opened this issue Sep 26, 2024 · 2 comments · May be fixed by #3281
Labels
bug Something isn't working topic: jsonpath

Comments

@quantonganh
Copy link

quantonganh commented Sep 26, 2024

What is the current bug behavior?

Given the following response:

{
    "data": [
        {
            "id": 1
        },
        {
            "id": 2
        }
    ]
}

If I want to get the first item with id equal to 1:

[Captures]
id: jsonpath "$.data[?(@.id == 1)].id" nth 0

This successfully returns:

* Captures:
* id: 1

However, when I attempt to get the first item with an id not equal to 1:

id: jsonpath "$.data[?(@.id != 1)].id" nth 0

I encounter the following error:

error: Invalid JSONPath
  --> test.hurl:4:14
   |
   | GET http://localhost:8888/api/v1/items
   | ...
 4 | id: jsonpath "$.data[?(@.id != 1)].id" nth 0
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^ the JSONPath expression '$.data[?(@.id != 1)].id' is not valid
   |

What is the expected correct behavior?

The expression should return:

* Captures:
* id: 2

Execution context

  • Hurl Version (hurl --version):
$ hurl --version
hurl 5.0.1 (x86_64-apple-darwin21.0) libcurl/7.79.1 (SecureTransport) LibreSSL/3.3.5 zlib/1.2.11 nghttp2/1.45.1
Features (libcurl):  alt-svc AsynchDNS HSTS HTTP2 IPv6 Largefile libz NTLM NTLM_WB SPNEGO SSL UnixSockets
Features (built-in): brotli
@quantonganh quantonganh added the bug Something isn't working label Sep 26, 2024
@lepapareil
Copy link
Collaborator

lepapareil commented Sep 26, 2024

Doesn't work either using $.data[?(!(@.id == 1))] :

 4 | id: jsonpath "$.data[?(!(@.id == 1))]" nth 0
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^ the JSONPath expression '$.data[?(!(@.id == 1))]' is not valid

or $.data[?(@.id < 1 || @.id > 1)] :

 4 | id: jsonpath "$.data[?(@.id < 1 || @.id > 1)]" nth 0
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the JSONPath expression '$.data[?(@.id < 1 || @.id > 1)]' is not valid

@fabricereix
Copy link
Collaborator

Thanks @quantonganh for your issue.
The support for filter is indeed quite limited.
But we should definitely work on it.
There is now a spec that we can follow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working topic: jsonpath
Projects
None yet
3 participants