I use javax to create JsonObject
and JsonArray
from my List<String>
and I have a list of Json objects that i want to put in a JsonObject
through a JsonArray
JsonArrayBuilder jsonArray = Json.createArrayBuilder();
for (String Obj : listOfJsonDfObjects)
jsonArray.add(summaryObj); //{"a":"b"},{"c":"d"}
// this line introduces extra escaping quotes like this {""a"":""b""},{""c"":""d""}
javax.json.JsonObject data = Json.createObjectBuilder()
.add("data", jsonArray.build()).build();
How to avoid these extra quotes escaping characters?
Thanks
2
Answers
Using Gson
A more secure way (to avoid altering original data)
You say you have a list of JSON objects, but you really have a list of JSON-formatted strings. To add them to a
JsonArray
, you need to parse each one into the JSON object model: