JSON.simple - Merging Arrays


Advertisements

In JSON.simple, we can merge two JSON Arrays easily using JSONArray.addAll() method.

Following example illustrates the above concept.

Example

import java.io.IOException;
import org.json.simple.JSONArray;

class JsonDemo {
   public static void main(String[] args) throws IOException {
      JSONArray list1 = new JSONArray();
      list1.add("foo");
      list1.add(new Integer(100));

      JSONArray list2 = new JSONArray();       
      list2.add(new Double(1000.21));
      list2.add(new Boolean(true));
      list2.add(null);

      list1.addAll(list2);       
      System.out.println(list1);       
   }
}

Output

["foo",100,1000.21,true,null]
Advertisements