You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I'm trying to match a json path partially, but I'm not sure how to do it.
Here's what I have:
varclient=newHttpClient();varserver=WireMockServer.Start();// this matchvartest1=new{things=new{name="RequiredThing"}};// this does not matchvartest2=new{things=new{name="RequiredThing"},soup="carrot"};server.Given(WireMock.RequestBuilders.Request.Create().WithPath("/test1").UsingPost().WithBody(newJsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"))).RespondWith(WireMock.ResponseBuilders.Response.Create().WithHeader("Content-Type","application/json").WithStatusCode(200).WithDelay(TimeSpan.FromMilliseconds(50)));server.Given(WireMock.RequestBuilders.Request.Create().WithPath("/test2").UsingPost().WithBody(newJsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"))).RespondWith(WireMock.ResponseBuilders.Response.Create().WithHeader("Content-Type","application/json").WithStatusCode(200).WithDelay(TimeSpan.FromMilliseconds(50)));varresponse1=awaitclient.PostAsJsonAsync($"http://localhost:{server.Port}/test1",test1);response1.EnsureSuccessStatusCode();varresponse2=awaitclient.PostAsJsonAsync($"http://localhost:{server.Port}/test2",test2);response2.EnsureSuccessStatusCode();
My expectation is that both requests match, but the second one fails.
The same approach using JmesPathMatching works fine.
Activity
StefH commentedon May 2, 2025
@hmiguel
In that case, did you try these?
StefH commentedon Dec 5, 2025
@hmiguel
In that case, did you try these?
https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching-JsonPartialMatcher
https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching-JsonPartialWildcardMatcher