JSONObject.put string method adding extra \ character to JSON String

JSONObject jsonObj = new JSONObject(json);

jsonObj.get("products");

JSONObject newJsonObj = new JSONObject();
newJsonObj.put("whatever", jsonObj.get("products"));

If you want to keep the json without escaping you need to add the jsonObject to an JsonArray.

JSONArray jsonArray = new JSONArray();
jsonArray.put(jsonObj);

and get it back later with

for (int i = 0; i < jsonArray.length(); i++)  { 
    JSONObject jsonObj = jsonArray.getJSONObject(i); 
 // then you can start filtering out the array.
    if (jsonObj.has("products")) {
         JSONArray nJsonArray = new JSONArray(jsonObj.get("products"));
          for (......) {} 
}

Tags:

Json

Android