Orange-OpenSource / hurl

Hurl, run and test HTTP requests with plain text.
https://hurl.dev
Apache License 2.0
13.06k stars 487 forks source link

Cannot use JSONPath to get keys #1464

Open janwytze opened 1 year ago

janwytze commented 1 year ago

What is the current bug behavior?

I cannot use JSONPath to receive object keys.

Steps to reproduce

This is the object I try to get keys from:

{
  "id": 1,
  "attachments": {
    "key1": {
      "created_at": "2023-04-18T11:22:36Z"
    },
    "key2": {
      "created_at": "2023-04-18T11:22:36Z"
    },
    "key3": {
      "created_at": "2023-04-18T11:22:36Z"
    }
  }
}

The following JSONPath queries do not work:

What is the expected correct behavior?

I would expect one of the above to work. The result should be the following:

[
"key1",
"key2",
"key3"
]

Execution context

fabricereix commented 1 year ago

Hi @janwytze, Indeed this is currently not supported in Hurl. We are not sure about this extension not present in the "official" spec https://goessner.net/articles/JsonPath/.

We might add a filter instead, that should be more readable and reusable. with your example

jsonpath "$.attachments" keys nth 0 == "key1"
jsonpath "$.attachments" keys nth 1 == "key2"
jsonpath "$.attachments" keys nth 2 == "key3"
janwytze commented 1 year ago

Thanks for the response! I can right now solve it by using a count instead