I have request JSON body
    
    [ 
      {"name" : "Ram"},
      {"name" : "Sam"}
    ]
and this is the input for wiremock request
I need to match the request even if the JSON has same content but values may not be in same order. Example,
    
    [ 
      {"name" : "Sam"},
      {"name" : "Ram"}
    ]
The method which I use is .withRequestBody. I tried withequalToJson` but does not work. What is that matcher which checks only JSON contents and not order ?
This can be resolved using JsonPath that is part of the bodyPatterns equality matching functionality.
{
  "request" : {
    "urlPathPattern" : "/jpath/.*",
    "method" : "GET",
     "bodyPatterns" : [ {
      "matchesJsonPath" : "$[?(@.name == 'Sam')]"
    } ]   
  },
  "response" : {
    "status" : 200,
    "body" : "Works"
  }
}
Using a JsonPath online evaluator it is easy to test JsonPath expressions. For more details on what is possible have a look here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With