1

I am new to JMeter java and Minidev. I am working on this existing module where I have to use minidev libraries I need to convert a JSON form non-indented format to a string format in Jmeter. The API requires a String representation of the JSON due to some characters.

To give an example, I have {"Item":"Value","MyList":["A","B","C"]} which I want to convert as "{\"Item\":\"Value\",\"MyList\":[\"A\",\"B\",\"C\"]}"

I have tried using JSONObject.toString() or JSONObject.toJSONString() however this does not give me desired results. I am using Jmeter 5 with Java 12

I did not find any good solution in short time so right now I am using below code however I would love to do it the right way.

String postJSON = root.toJSONString().replace("\"","\\\"");
postJSON = postJSON.replace("{","\"{");
postJSON = postJSON.replace("}","}\"");
I 2
  • 13
  • 4

0 Answers0