Orange-OpenSource / hurl

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

Allow includes prediate to check for object in collection #2232

Open RyanEager-TensorIoT opened 11 months ago

RyanEager-TensorIoT commented 11 months ago

Problem to solve

I have an API which returns a collection of JSON objects and I want to check their values. I can check that the values exist within the collection with:

jsonpath "$.books[*].title includes "Introduction to Algorithms"
jsonpath "$.books[*].author includes "Thomas H. Cormen"

but I can not confirm that the these values are within the same object.

Proposal

Allow the includes predicate to check for a object within a collection, i.e for the collection:

books: [
    {
        "title":  "Introduction to Algorithms",
        "author": "Thomas H. Cormen",
        "publisher": "The MIT Press"
    },
    ...
]

You can check with an object:

jsonpath "$.books includes 
{
    "title":  "Introduction to Algorithms",
    "author": "Thomas H. Cormen", 
}

or one in a variable:

jsonpath "$.books includes {{myAwesomeBook}}

This would return true even if the object in the collection has additional keys. i.e. the above examples would return True.

Additional context and resources

Yevgnen commented 4 months ago

Any updates?