Question: JsonPathMatcher - not matching? Correct syntax? #89

Closed
opened 2025-12-29 08:22:03 +01:00 by adam · 4 comments
Owner

Originally created by @rangerranger on GitHub (Apr 9, 2018).

Hi - I'm not having my json match with the JsonPathMatcher. For example, I use:

Request.Create().WithPath("/api/beta03").UsingPost()
    .WithBody(new JsonPathMatcher("{Scope:[{Sources:[{Shard:\"beta03\"}]}]}"))

But it never matches that request. Does the "pattern" to JsonPathMatcher have to be in a specific syntax?
I ended up adding a JsonExactMatcher (that just matches json exactly), since the JsonPathMatcher wasn't working for me. Could you suggest if something is wrong with the above code?

Originally created by @rangerranger on GitHub (Apr 9, 2018). Hi - I'm not having my json match with the JsonPathMatcher. For example, I use: ``` c# Request.Create().WithPath("/api/beta03").UsingPost() .WithBody(new JsonPathMatcher("{Scope:[{Sources:[{Shard:\"beta03\"}]}]}")) ``` But it never matches that request. Does the "pattern" to JsonPathMatcher have to be in a specific syntax? I ended up adding a JsonExactMatcher (that just matches json exactly), since the JsonPathMatcher wasn't working for me. Could you suggest if something is wrong with the above code?
adam closed this issue 2025-12-29 08:22:04 +01:00
Author
Owner

@kwucode commented on GitHub (Apr 10, 2018):

Please see JSONPath syntax.

@kwucode commented on GitHub (Apr 10, 2018): Please see [JSONPath syntax](http://goessner.net/articles/JsonPath).
Author
Owner

@rangerranger commented on GitHub (Apr 10, 2018):

Thanks Kevin. I guess in terms of json path syntax i need “$..*” - to match all members of my json exactly?
How would i create the request object in the above code?

@rangerranger commented on GitHub (Apr 10, 2018): Thanks Kevin. I guess in terms of json path syntax i need “$..*” - to match all members of my json exactly? How would i create the request object in the above code?
Author
Owner

@StefH commented on GitHub (May 17, 2018):

The latest version from WireMock does now also support using a normal WildcardMatcher if you want to match a json message.

So this code should also work like this example:

Request.Create().WithPath("/api/beta03").UsingPost()
    .WithBody("*beta03*"))
@StefH commented on GitHub (May 17, 2018): The latest version from WireMock does now also support using a normal WildcardMatcher if you want to match a json message. So this code should also work like this example: ``` c# Request.Create().WithPath("/api/beta03").UsingPost() .WithBody("*beta03*")) ```
Author
Owner

@StefH commented on GitHub (Jul 2, 2018):

A new JsonMatcher has been added in latest version which enables you to match a json object 1:1.

See also https://github.com/WireMock-Net/WireMock.Net/issues/154

Closing this issue now...

@StefH commented on GitHub (Jul 2, 2018): A new `JsonMatcher` has been added in latest version which enables you to match a json object 1:1. See also https://github.com/WireMock-Net/WireMock.Net/issues/154 Closing this issue now...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#89