'How to correctly generate Json without Backslashes

Problem:

I get json with backslashes as response from a GET Request

@RequestMapping(value = "repuve/recibe_captcha", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)

like this:

{"mensaje":"Proceso ejecutado correctamente.","folio":"1652989601959","resultado":"{\"idSalida\":1,\"descSalida\":\"Proceso Correcto\",\"data\":[.....]}"}

When expected Result is like this:

{"mensaje":"Proceso ejecutado correctamente.","folio":"1652989601959","resultado":"{"idSalida":1,"descSalida":"Proceso Correcto","data":[.....]}"}

(The data array has a b64 image).

This is how json is created:

JSONObject object = new JSONObject();
JSONArray jArray = new JSONArray();
object.put("idSalida", 1);
object.put("descSalida", "Proceso Correcto");
jArray.put(captcha);
object.put("data", jArray);

I've tried some answers from StackOverflow using replace() but none of them seems to work for me.

Is there another way to remove the backslashes and get the correct json format delivered to front?

Thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source