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

JsonPathMatcher filter does not work with non array JSON #655

Closed
bettyybei opened this issue Oct 16, 2021 · 4 comments
Closed

JsonPathMatcher filter does not work with non array JSON #655

bettyybei opened this issue Oct 16, 2021 · 4 comments
Labels

Comments

@bettyybei
Copy link

bettyybei commented Oct 16, 2021

Describe the bug

JsonPathMatcher does not allow the usage of filters with non array JSON.
In the example provided in the wiki, the first matching example listed { "things": { "name": "RequiredThing" } } does not actually request match with the body matcher pattern "$.things[?(@.name == 'RequiredThing')]".

Expected behavior:

JsonPathMatcher filters should work with non array JSON

Test to reproduce

  • Set body matcher pattern to "$.things[?(@.name == 'RequiredThing')]"
  • Send request with JSON body { "things": { "name": "RequiredThing" } }

Expected behavior: Returns request match
Actual behavior: Does not match

Other related info

  • This behavior may have been broken in fix jsonpath matcher #311
  • The other example in the wiki { "things": [ { "name": "RequiredThing" }, { "name": "Wiremock" } ] } works correctly because { "name": "RequiredThing" } is in an array.
  • I believe outside of wiremock, JSONPath filters are actually only supposed to be used with arrays, so this may not actually be a bug. If so, the wiki should be updated. However, I believe there is still value in allowing the ability to use filters for non-array JSON matches, otherwise there does not seem to be a way to request match multiple JSON properties without doing an exact match of all properties using JsonMatcher. (I believe JsonPartialMatcher only allows you to match 1 property, but let me know if I'm wrong about this).
@bettyybei bettyybei added the bug label Oct 16, 2021
@StefH
Copy link
Collaborator

StefH commented Oct 23, 2021

Hello @bettyybei, thank you for this issue.

I did some research, and I think that the JsonPathMatcher works fine, but the examples are wrong.

The following code works fine

var things = JObject.Parse("{ \"things\": { \"name\": \"RequiredThing\" } }");
JToken wiremockOK = things.SelectToken("[?($.things.name == 'RequiredThing')]");
wiremockOK.Dump();

image

Does this make sense?

@StefH StefH added question and removed bug labels Feb 20, 2022
@StefH
Copy link
Collaborator

StefH commented Feb 20, 2022

@bettyybei
Did you have time to verify this? Else I will close this question.

@StefH
Copy link
Collaborator

StefH commented May 3, 2022

@bettyybei
Did you have time to verify this? Else I will close this question.

@StefH
Copy link
Collaborator

StefH commented Aug 25, 2022

Hello @bettyybei,

I'll close this issue for now, in case you still have questions, please reply to this comment.

@StefH StefH closed this as completed Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants