Java Requires Chilkat v11.0.0+
Chilkat2 Java
Copy JSON Object from one JSON Array to Another
See more JSON Examples
Demonstrates how to copy an object in a JSON array to another JSON array.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.JsonArray;
import com.chilkatsoft.chilkat2.JsonObject;
public class ChilkatExample {
public static void main(String[] args) {
JsonArray arr1 = new JsonArray();
JsonArray arr2 = new JsonArray();
String s = "[{\"a\":1}, {\"b\":2}, {\"c\":3}]";
String sEmpty = "[]";
arr1.load(s);
arr2.load(sEmpty);
JsonObject jObj = new JsonObject();
arr1.objectAt2(1, jObj);
arr2.addObjectCopyAt(-1, jObj);
System.out.println(arr2.emit());
// output is: [{"b":2}]
}
}