jsonstringgroovyjmeterjsr223

Convert json values inside a variable to String in Jmeter


I am using Json extractor to filter some json values from an API's response and need to pass the same data as Payload in another API. Problem is values captured under the variable are not in string format ,but in json format which cant be passed in subsequent api's payload. That API is expecting the stringified format as payload. Any help?

(Expected format eg: "[{"0":"loc #","1":"sub-loc #"} ) (What is getting saved in variable : [{"0":"loc #","1":"sub-loc #"}

What i can think of is to convert the variable value into string and pass it in subsequent api or JSR223 post processor to convert it? Any other way?


Solution

    1. I don't see any difference between [{"0":"loc #","1":"sub-loc #"} and [{"0":"loc #","1":"sub-loc #"}

    2. JSON is a string, like any JSON could be a string but not any string can be a JSON, take a look at https://json.org:

      JSON is a text format that is completely language independent

    3. If you need to pass the whole response to the next request instead of using JSON Extractor switch to Boundary Extractor and leave left and right boundaries empty. In this case the full response will be stored into a JMeter Variable (which is a String by design)