How to create a implement a JsonMatcher or JsonPartialMatcher With Regex? #378

Closed
opened 2025-12-29 15:22:17 +01:00 by adam · 6 comments
Owner

Originally created by @AndresGMD on GitHub (Oct 20, 2021).

Hello every one!!

In the case I would like to implement a Json Matcher just for detect Json Keys for any Value.

Body": {
        "Matcher": {
          "Name": "JsonPartialMatcher",
          "Pattern": {
            "person": [
              {
                "id": "*",
                "name": "*",
                "age": "*",
                "Height": "*",
                "gender": "*"
              }
            ]
          }
        }

How can this be implemented? Thanks in advance

Originally created by @AndresGMD on GitHub (Oct 20, 2021). Hello every one!! In the case I would like to implement a Json Matcher just for detect Json Keys for any Value. ``` Body": { "Matcher": { "Name": "JsonPartialMatcher", "Pattern": { "person": [ { "id": "*", "name": "*", "age": "*", "Height": "*", "gender": "*" } ] } } ``` How can this be implemented? Thanks in advance
adam added the question label 2025-12-29 15:22:17 +01:00
adam closed this issue 2025-12-29 15:22:17 +01:00
Author
Owner

@StefH commented on GitHub (Oct 23, 2021):

@andresendava
Please explain in more detail what you want to match (add some examples)

@StefH commented on GitHub (Oct 23, 2021): @andresendava Please explain in more detail what you want to match (add some examples)
Author
Owner

@AndresGMD commented on GitHub (Oct 25, 2021):

Hi Stef,

Off course.

I would like to know how I can further validate the structure with any value. Example:

This is my Dataset I would like to validate.

{
  "person": [
    {
      "id": "ANY VALUE",
      "name": "ANY VALUE",
      "age": "ANY VALUE",
      "Height": "ANY VALUE",
      "gender": "ANY VALUE"
    }
  ]
}

If I Include Another Dataset in Request Body (Change Name with Las Name):

{
  "person": [
    {
      "id": "ANY VALUE",
      "Last name": "ANY VALUE",
      "age": "ANY VALUE",
      "Height": "ANY VALUE",
      "gender": "ANY VALUE"
    }
  ]
}

The result will be:

{
    "Status": "No matching mapping found"
}

Thanks in advance

@AndresGMD commented on GitHub (Oct 25, 2021): Hi Stef, Off course. I would like to know how I can further validate the structure with any value. Example: This is my Dataset I would like to validate. ``` { "person": [ { "id": "ANY VALUE", "name": "ANY VALUE", "age": "ANY VALUE", "Height": "ANY VALUE", "gender": "ANY VALUE" } ] } ``` If I Include Another Dataset in Request Body (Change Name with Las Name): ``` { "person": [ { "id": "ANY VALUE", "Last name": "ANY VALUE", "age": "ANY VALUE", "Height": "ANY VALUE", "gender": "ANY VALUE" } ] } ``` The result will be: ``` { "Status": "No matching mapping found" } ``` Thanks in advance
Author
Owner

@StefH commented on GitHub (Oct 26, 2021):

@andresendava

I've created a new matcher : "JsonPartialWildcardMatcher" which can be used like:

{
  "person": [
    {
      "id": "*"
    }
  ]
}

will match:

{
  "person": [
    {
      "id": "xxxx"
    }
  ]
}

This new code is present in a preview build version : 1.4.24-ci-15542.

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

PR
https://github.com/WireMock-Net/WireMock.Net/pull/667

@StefH commented on GitHub (Oct 26, 2021): @andresendava I've created a new matcher : "JsonPartialWildcardMatcher" which can be used like: ``` json { "person": [ { "id": "*" } ] } ``` will match: ``` json { "person": [ { "id": "xxxx" } ] } ``` This new code is present in a preview build version : `1.4.24-ci-15542`. See https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions PR https://github.com/WireMock-Net/WireMock.Net/pull/667
Author
Owner

@AndresGMD commented on GitHub (Oct 26, 2021):

Hi @StefH

Thanks a lot!.

Additional info: For Install in MAC I check Include prerelease & and I have to update all WireMock Packages.

@AndresGMD commented on GitHub (Oct 26, 2021): Hi @StefH Thanks a lot!. Additional info: For Install in MAC I check Include prerelease & and I have to update all WireMock Packages.
Author
Owner

@AndresGMD commented on GitHub (Oct 27, 2021):

It is working very well

Wrong dataset:

image

Correct dataset

image image
@AndresGMD commented on GitHub (Oct 27, 2021): It is working very well Wrong dataset: <img width="640" alt="image" src="https://user-images.githubusercontent.com/90065355/138989040-a0d405ba-fe8f-4ca4-b900-1f886f913a14.png"> Correct dataset <img width="655" alt="image" src="https://user-images.githubusercontent.com/90065355/138989111-c96d8433-00d4-45e5-8d19-cd41d6183686.png"> <img width="653" alt="image" src="https://user-images.githubusercontent.com/90065355/138989173-497782c7-d8cb-4aca-8426-a09a2167cd43.png">
Author
Owner

@StefH commented on GitHub (Oct 27, 2021):

Hello @andresendava ,

Thank you for testing. I'll merge the PR and in some time this functionality is also present in official nuget.

@StefH commented on GitHub (Oct 27, 2021): Hello @andresendava , Thank you for testing. I'll merge the PR and in some time this functionality is also present in official nuget.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#378