Unable to implement variable in HTTP Body

Hi all!

I have a HTTP body that I’m using to POST to an address. I have implemented variables into most of the body but I am struggling to implement one more variable as it seems to give me an error as the Body is not what the address is expecting. It could have something to do with the " after “data”: but I’m not sure.

Here is the body.

{“customerKey”:"${customerKey}",“deviceId”:"${deviceID}",“token”:"${token}",“skipEncryption”:true,“sessionID”:"${deviceID}",“action”:“create_serviceoperationfieldtypes_test”,“object”:"",“subapp”:“trin_serviceoperationfieldtype_test”,“gpsCoords”:{“latitude”:0,“longitude”:0,“altitude”:0,“direction”:0,“speed”:0,“horizontalAccuracy”:0,“verticalAccuracy”:0,“timestamp”:""},“userName”:"${userName}",“data”:{“region”:{"_sv":{“enter_long_defaull”:“1”,“fieldbool”:“true”,“fieldfloat”:1,“fieldint”:1,“fieldstring”:“A”,“long_def”:“1”,“long_no_def”:“1”},“enter_long_defaull”:“1”,“fieldbool”:“true”,“fieldfloat”:1,“fieldint”:1,“fieldstring”:“A”,“long_def”:“1”,“long_no_def”:“1”}},“logUserID”:""}

I want to condense the Bolded part into a variable nested within “data”:

Thanks!

you have to use single quotes when you build your variable, to avoid any interpolation attempt.
something like this should work:

longVar = '{“region”:{"_sv":{“enter_long_defaull”:“1”,“fieldbool”:“true”,“fieldfloat”:1,“fieldint”:1,“fieldstring”:“A”,“long_def”:“1”,“long_no_def”:“1”},“enter_long_defaull”:“1”,“fieldbool”:“true”,“fieldfloat”:1,“fieldint”:1,“fieldstring”:“A”,“long_def”:“1”,“long_no_def”:“1”}'
print longVar

and use it like this:

"data":${longVar}

Not sure on the ‘{}’ … if they are missing from your variable value you may have to escape them … but in theory with single quoted strings the curly braces should be picked also as they are …

see this for reference:
http://docs.groovy-lang.org/latest/html/documentation/index.html#all-strings