I’m using WireMock Standalone to mock API responses, and I need to dynamically calculate values within my response templates. Specifically, I want to perform basic arithmetic operation (multiplication) on values extracted from the request.
{
"price": {{jsonPath node $.price}},
"quantity": {{jsonPath node $.quantity}},
"amt": {{multiply (parseInt (this.price)) (parseFloat (this.quantity))}}
}
To achieve the desired outcome, I need to multiply the ‘price’ and ‘quantity’ values (are of type string) and store the result in a new key named ‘amt’ within the JSON response. However, I’m encountering a couple of challenges:
parseInt
&parseFloat
are not a valid functions in this context. I need to help on how to correctly convert this toint
/floats
beforehand to multiply them.- I’m uncertain about how to correctly reference the keys
price
andquantity
within the same JSON response template.”
Open to other suggestions as well.
TIA.