Regex support for JsonMatcher #588

Closed
opened 2025-12-29 15:27:43 +01:00 by adam · 10 comments
Owner

Originally created by @pluma9 on GitHub (Mar 31, 2024).

Originally assigned to: @StefH on GitHub.

Is your feature request related to a problem? Please describe.
I'd like to use regex in JsonMatcher (just like in JsonPartialMatcher)

Describe the solution you'd like
Add the option to turn on regex. Similar to: https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching-JsonPartialMatcher#use-regex

Describe alternatives you've considered
No alternative solution I can think of

Is your feature request supported by WireMock (java version)? Please provide details.
I am not sure. Please let know if this is important. I can do some more research.

Additional context
No.

Originally created by @pluma9 on GitHub (Mar 31, 2024). Originally assigned to: @StefH on GitHub. **Is your feature request related to a problem? Please describe.** I'd like to use regex in JsonMatcher (just like in JsonPartialMatcher) **Describe the solution you'd like** Add the option to turn on regex. Similar to: https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching-JsonPartialMatcher#use-regex **Describe alternatives you've considered** No alternative solution I can think of **Is your feature request supported by [WireMock (java version)](https://www.wiremock.org)? Please provide details.** I am not sure. Please let know if this is important. I can do some more research. **Additional context** No.
adam added the feature label 2025-12-29 15:27:43 +01:00
adam closed this issue 2025-12-29 15:27:43 +01:00
Author
Owner

@StefH commented on GitHub (Apr 2, 2024):

@pluma9
I'll see if this can be added easily.

Is there a reason you cannot use the JsonPartialMatcher ?

@StefH commented on GitHub (Apr 2, 2024): @pluma9 I'll see if this can be added easily. Is there a reason you cannot use the JsonPartialMatcher ?
Author
Owner

@pluma9 commented on GitHub (Apr 3, 2024):

Thanks. That is because I want to assert that the request contains exactly certain fields. Adding more fields may make the real API server returns an error.

@pluma9 commented on GitHub (Apr 3, 2024): Thanks. That is because I want to assert that the request contains exactly certain fields. Adding more fields may make the real API server returns an error.
Author
Owner

@StefH commented on GitHub (Apr 4, 2024):

I've added this logic, can you please test preview version WireMock.Net.1.5.51-ci-18462?

See https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

@StefH commented on GitHub (Apr 4, 2024): I've added this logic, can you please test preview version `WireMock.Net.1.5.51-ci-18462`? See https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions
Author
Owner

@pluma9 commented on GitHub (Apr 5, 2024):

Thanks very much. It works great in terms of regex.

There seems to be a regression.
Given JsonMatcher:

{
  "Contact": {
    "Phone": "1234",
    "Street": "King Street"
  },
  "Info": {
    "Occupation": "Developer"
  }
}

In previous versions, it does not match the following body:

{
  "Contact": {
    "Phone": "1234",
    "Street": "King Street"
  },
  "Info": {
    "Occupation": "Developer"
  },
  "OtherInfo": {
    "NickName": "Jimmy"
  }
}

However, in WireMock.Net.1.5.51-ci-18462, it does

@pluma9 commented on GitHub (Apr 5, 2024): Thanks very much. It works great in terms of regex. There seems to be a regression. Given `JsonMatcher`: ```json { "Contact": { "Phone": "1234", "Street": "King Street" }, "Info": { "Occupation": "Developer" } } ``` In previous versions, it does **not** match the following body: ```json { "Contact": { "Phone": "1234", "Street": "King Street" }, "Info": { "Occupation": "Developer" }, "OtherInfo": { "NickName": "Jimmy" } } ``` However, in WireMock.Net.1.5.51-ci-18462, it **does**
Author
Owner

@StefH commented on GitHub (Apr 5, 2024):

I see.
Thanks for this observation.

I need to adjust the logic to match exact. I'll check tomorrow.

@StefH commented on GitHub (Apr 5, 2024): I see. Thanks for this observation. I need to adjust the logic to match exact. I'll check tomorrow.
Author
Owner

@StefH commented on GitHub (Apr 6, 2024):

@pluma9
It's fixed.

Can you please test preview WireMock.1.5.51-ci-18469 ?

@StefH commented on GitHub (Apr 6, 2024): @pluma9 It's fixed. Can you please test preview `WireMock.1.5.51-ci-18469` ?
Author
Owner

@pluma9 commented on GitHub (Apr 6, 2024):

The previous case works great now.

However, there is one more case. Given the matcher above, the following body does not match (expected):

{
  "Contact": {
    "Phone": "1234",
    "Street": "King Street"
  },
  "Info": {
    "Occupation": "Dancer"
  }
}

The following body oddly matches:

{
  "Contact": {
    "Phone": "1234",
    "Street": "King Street"
  },
  "Info": {
    "Occupation": "Developer2"
  }
}
@pluma9 commented on GitHub (Apr 6, 2024): The previous case works great now. However, there is one more case. Given the matcher above, the following body does not match (expected): ```json { "Contact": { "Phone": "1234", "Street": "King Street" }, "Info": { "Occupation": "Dancer" } } ``` The following body oddly matches: ```json { "Contact": { "Phone": "1234", "Street": "King Street" }, "Info": { "Occupation": "Developer2" } } ```
Author
Owner

@StefH commented on GitHub (Apr 6, 2024):

All strings should be defined as valid regular expressions.

So in this case like this:

^Developer2$

@StefH commented on GitHub (Apr 6, 2024): All strings should be defined as valid regular expressions. So in this case like this: `^Developer2$`
Author
Owner

@pluma9 commented on GitHub (Apr 6, 2024):

Ah, I see. Then things work great now.

I really appreciate your support.

@pluma9 commented on GitHub (Apr 6, 2024): Ah, I see. Then things work great now. I really appreciate your support.
Author
Owner

@StefH commented on GitHub (Apr 6, 2024):

I'll merge the PR and create a new normal NuGet soon.

@StefH commented on GitHub (Apr 6, 2024): I'll merge the PR and create a new normal NuGet soon.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#588