import net.minidev.json.parser.JSONParser;
import net.minidev.json.JSONObject;
import net.minidev.json.JSONArray;
JSONParser p = new JSONParser(JSONParser.MODE_PERMISSIVE);
String response = prev.getResponseDataAsString();
JSONObject jsonresponse = (JSONObject) p.parse(response);
JSONObject json2 = (JSONObject) jsonresponse.get("Key1");
JSONObject newjson = new JSONObject();
newjson.put("displayValue", json2.get("displayValue"));
newjson.put("value", json2.get("value"));
jsonresponse.put("Key2", newjson);
if(jsonresponse.has("Key3"))
{
jsonresponse.remove("Key3");
jsonresponse.put("Key3", jsonresponse.get("Key3").get("value");
}
log.info(jsonresponse.toString());
I need to enter the if loop to remove the json key value if it exists and replace it with something else.
if(jsonresponse.has("Key3"))
line to if(jsonresponse.containsKey("Key3"))