-2

I was wondering how I would go about combining two JSON objects I have as shown below. I'm using Java.

Input
array1 = {"color":"red",
          "day":"Monday",
          "week":"2",
          "numbers":{"odd":"1","even":"2"},"items":[]};
array2 = {"color":"blue",
          "day":"Friday",
          "numbers":{"odd":"3","even":"4"},
          "items":[{"potato":"cooked",
                    "bread":"toasted"}]};

Output
combined array = {
      array1: 
         {"color":"red",
          "day":"Monday",
          "week:"2",
          "numbers":{"odd":"1","even":"2"},"items":[]};
      array2:
         {"color":"blue",
          "day":"Friday",
          "numbers":{"odd":"3","even":"4"},
          "items":[{"potato":"cooked",
                    "bread":"toasted"}]};
}

As shown above, I get two different JSON objects and combine them into one JSON and return it. Does anyone have an easy way to do this?

0 Answers0