Skip to content

Support indexing on arrays in body matching#339

Merged
fbryden merged 6 commits intomainfrom
fbryden/config_v2_body_matching_arrays
Apr 1, 2026
Merged

Support indexing on arrays in body matching#339
fbryden merged 6 commits intomainfrom
fbryden/config_v2_body_matching_arrays

Conversation

@fbryden
Copy link
Copy Markdown
Contributor

@fbryden fbryden commented Mar 30, 2026

Indexing is currently not supported in the body matching path of config v2.

This adds support for it.

Allows two scenarios, where we attempt scenario 1, and fallback to scenario 2 in case we don't find a value at that path.

The query path is a.b.0.c. Both scenarios will match.

Scenario 1

{
  "a": {
    "b": [
      {
        "c": "value"
      }
    ]
  }
}

Scenario 2

{
  "a": {
    "b": {
      "0": {
        "c" : "value"
      }
    }
  }
}

@fbryden fbryden requested a review from a team as a code owner March 30, 2026 14:55
@aimenebelfodil
Copy link
Copy Markdown
Contributor

More of a curisotiy? @fbryden why a.b.0.c and not a.b[0].c
https://www.rfc-editor.org/rfc/rfc9535#name-array-slice-selector 🙇

@fbryden
Copy link
Copy Markdown
Contributor Author

fbryden commented Mar 31, 2026

@aimenebelfodil
sort of a fair suggestion, but it heavily simplifies the parsing of the path string.
Your suggestion requires slightly more complex parsing.

@@ -162,7 +162,14 @@ fn matches_body(body_matcher: &BTreeMap<String, BodyMatcher>, body: &str) -> boo
let parts = path.split('.');
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aimenebelfodil we currently split on . and treat each element as a way to traverse one layer deeper

@@ -162,7 +162,14 @@ fn matches_body(body_matcher: &BTreeMap<String, BodyMatcher>, body: &str) -> boo
let parts = path.split('.');
Copy link
Copy Markdown
Contributor

@vinckama vinckama Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to treat arrays path differently than maps? For instance, would it be possible to follow the jsonpath syntax? It's the same syntax used in synthetics to validate the body response.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aimenebelfodil @vinckama I've implemented jsonpath-like accessing in 4393fa1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙇

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, I did not see the comment at that time. Thanks for pushing this 🙇

Copy link
Copy Markdown
Contributor

@aimenebelfodil aimenebelfodil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks

  • Could you add a test where root is an array?
  • Another test where we do have nested array
  • And update the PR description too 🙇 with the latest updates

Thanks @fbryden 🥇

@fbryden fbryden merged commit ded1d66 into main Apr 1, 2026
4 checks passed
@fbryden fbryden deleted the fbryden/config_v2_body_matching_arrays branch April 1, 2026 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants