Forum Discussion

basinilya's avatar
basinilya
Occasional Visitor
3 years ago

Need double-encoded JSON in request body

I created a POST method for a REST service and I want to use the method parameter as part of the request body, but not in a raw form, but encoded as a JSON string. I hope to achieve this using the groovy scriptlet syntax: %{= }

 

The parameter is a PLAIN parameter:

 

DependenciesJsonString=a"b

 

 (notice the unmatched quote). The body template is:

 

{
"DependenciesJsonString": "${= someEncodeJSON(getSomeParameter( "DependenciesJsonString" )) }"
}

and the desired effective body is:

{
"DependenciesJsonString": "a\"b"
}

I tried ${DependenciesJsonString}, but the resolved value becomes part of the expression causing syntax errors.

Upd: I kinda guessed that you can retrieve the property value like this:

testStep.properties["DependenciesJsonString"].value

 Is there a shorter syntax?

No RepliesBe the first to reply