Roger Williams
08/22/2023, 4:53 PM{
"number": "{{math 1 '*' (jsonPath request.body '$.value')}}"
}
The value
is coming in as a String and it needs to be an Integer when sent back. The math helper arithmetic operations work correctly but the response is always a String. What am I missing?Oleg Nenashev
08/22/2023, 5:29 PMLee Turner
08/22/2023, 5:47 PMjsonBody
element to define the response payload, the "
need to be there for it to be valid json. This means your integer will always go back as a string. If I change the jsonBody
to use the body
element instead I don’t have to worry about it being valid json so can remove those quotes. The downside is that you have to escape the json but it seems to work:
"response": {
"status": 202,
"headers": {
"Content-Type": "application/json"
},
"body": "{\"number\": {{math 1 '*' 3}} }",
"transformers": ["response-template"]
}
Results in:
{
"number": 3
}
Roger Williams
08/22/2023, 7:07 PM