Pavel Serada
01/20/2023, 5:15 PM{{{jsonPath request.body '$..paths[1].source'}}}
{
"request": {
"urlPattern": ".*/transfers",
"method": "POST"
},
"response": {
"status": 200,
"body": "{\"id\": \"{{{jsonPath request.body '$..paths[1].source'}}}\",
Request is a valid Json structure containing this part in its body, and I need to get blablablah2 from request body to return it in response body:
{
"paths": [
{
"source": "blablablah1",
"destination": "blablablah1"
},
{
"source": "blablablah2",
"destination": "blablablah2"
}
]
}
My issue is that Wiremock returns: "body": "{\"id\": \"[\"*blablablah2*\"]\",
and I'd like to get it without [ ]
, any idea why it's happening?
Actual: "body": "{\"id\": \"[\"*blablablah2*\"]\",
Expected: "body": "{\"id\": \"*blablablah2*\",
Tom
01/20/2023, 5:34 PM{{{jsonPath request.body '$..paths[1].source[0]'}}}
Aaron
01/20/2023, 5:36 PM.
between the $
and the rest of the expression. The following returned what you’d expect:
"response": {
"status": 200,
"body": "{\"id\": \"{{{jsonPath request.body '$.paths[1].source'}}}\" }"
}
{
"id": "blablablah2"
}
As for why… I don’t know 🤷🏻Tom
01/20/2023, 5:37 PM$..
is a query, meaning it always returns a list of results.
indicates a selector, which is potentially only one element.Aaron
01/20/2023, 5:38 PMTom
01/20/2023, 5:38 PMAaron
01/20/2023, 5:39 PMPavel Serada
01/20/2023, 5:39 PM