Sample code for 30+ languages & platforms
Java Requires Chilkat v11.0.0+

JSON AppendArray2 Example

Demonstrates the AppendArray2 function.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.JsonArray;
import com.chilkatsoft.chilkat2.JsonObject;

public class ChilkatExample {

    public static void main(String[] args) {
        JsonObject json = new JsonObject();
        json.load("{ \"name\": \"John\", \"marbles\": 100 }");

        // Append an empty array named "xyz"
        JsonArray jarr = new JsonArray();
        json.appendArray2("xyz", jarr);

        System.out.println(json.emit());
        // Expected output is:   {"name":"John","marbles":100,"xyz":[]}

        // Add elements to the array.
        jarr.addStringAt(-1, "hello");
        jarr.addIntAt(-1, 256);

        System.out.println(json.emit());
        // Expected output is:  {"name":"John","marbles":100,"xyz":["hello",256]}
    }
}