How to remove extra escaping quote characters of JsonObject created through Javax

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()

How to avoid these extra quotes escaping characters? Thanks


  • 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:

    public class JsonTest {
        public static void main(String[] args) {
            List<String> listOfJsonDfObjects = List.of(
            JsonArrayBuilder jsonArray = Json.createArrayBuilder();
            for (String summaryObj : listOfJsonDfObjects) {
                JsonReader parser = Json.createReader(new StringReader(summaryObj));
            JsonObject data = Json.createObjectBuilder()
            System.out.println(data); // {"data":[{"a":"b"},{"c":"d"}]}