I am trying to pass a string extracted from an API response in a subsequent call in JMeter. I am able to extract the object I want ("thing": "THING"
), store it as variable $thisThing
and then pass it, but not as a string.
Using this as my body data:
{ "foo": "bar", "thing": ${thisThing} }
…results in this request body:
{ "foo": "bar", "thing": THING, }
And the API errors out, unexpected token. Looking into post-processing solutions but I can’t dig up anything of relevance.
Advertisement
Answer
As per JSON Object Literals:
Keys must be strings, and values must be a valid JSON data type:
- string
- number
- object
- array
- boolean
- null
so if this THING
supposed to be a JSON String – you need to surround it with quotation marks:
{ "foo": "bar", "thing": "${thisThing}" }
or amend your Post-Processor configuration to extract the THING
value along with surrounding quotation marks.
You might also need to add a HTTP Header Manager and configure it to send Content-Type header with the value of application/json