In my project I convert list of maps to jsonArray. However, sometimes there are values which are maps, So I convert them to Strings then add them to the JSONArray. But when I do this, the apostrophes for each key and value is being replaced by backslash. For example, my expected result:
[{"user":"124545","count":"60"}]
actual result:
["{\"user\":\"124545\",\"count\":\"60\",}"]
My code snippet:
Map<String, String> map = row.getMap(i, String.class, String.class);
JSONObject objectMap= new JSONObject(map);
String cellData = objectMap.toString();
JSONArray array= new JSONArray();
array.put(cellData);
I'm running it through rows of query results of Cassandra database, so I have in the jsonArray regular values separated by comas, and sometimes map values.
objectMap.toString();to theJSONArrayrather than theobjectMapitself? - Sotirios DelimanoliscellDatais the JSON string representation ofobjectMap. You're double encoding it to JSON by adding it to thearray. Just usearray.put(objectMap). - Sotirios Delimanolis