JsonPathMatcher filter does not work with non array JSON
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 https://github.com/WireMock-Net/WireMock.Net/pull/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 believeJsonPartialMatcheronly allows you to match 1 property, but let me know if I'm wrong about this).
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();

Does this make sense?
@bettyybei Did you have time to verify this? Else I will close this question.
@bettyybei Did you have time to verify this? Else I will close this question.
Hello @bettyybei,
I'll close this issue for now, in case you still have questions, please reply to this comment.