Orange-OpenSource / Orange-OpenSource/hurl

Assert against every member of a JSONPATH collection?

Open
#347 4 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement topic: predicates
Dominant language
Rust
Stars
19.2k
Forks
745
Avg merge
5h 3m
Merged PRs (30d)
60

Description

Hi, I'm sorry if this is an ignorant question. Let's imagine an API which returns an array of elements:

{
  "data": [
    { "item": "value1" },
    { "item": "value2" },
    { "item": "value3" }
  ]
}

My basic use case is that I want to assert that all of the values of "item" match the pattern "value.*". Today it seems like I can do:

jsonpath "$.data[0].item" matches "value.*"

However I would really like a way to say:

jsonpath "$.data[*].item" matches "value.*"

That is to say, test each member against the regex. What seems to happen when I try this is that all of the items are concatenated, so that the match is against something like [string <value1>, string <value2>, string <value3>] (according to the output of hurl). I can see using https://jsonpath.com/ that this is due to the way jsonpath processes the input.

I tried to bend jsonpath to emit a collection of elements whose value does not match value.* (so I could assert that zero things remained) but couldn't figure it out.

Something I wondered along the way is whether it would make sense to be able to run the predicate on each value in a resultant collection. So jsonpath "$.data[*].item" EACH matches "value.*"

Thanks for your consideration! I have had good success using hurl to help me build an API gateway.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file or test is named. Start by locating Hurl's JSONPath assertion handling and the tests covering collection results and regex matching. Compare the current collection behavior with the proposed per-value assertion, then define tests that show the intended result for matching and non-matching members.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, testing-qa
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.