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

Example: JsonObject.NewArrayOf method

See more JSON Examples

Demonstrates the NewArrayOf method.

Chilkat Java Downloads

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

public class ChilkatExample {

    public static void main(String[] args) {
        String big_cats = "[\"lion\",\"tiger\",\"leopard\",\"jaguar\",\"cheetah\",\"snow leopard\",\"clouded leopard\",\"cougar\",\"puma\",\"panther\"]";

        JsonObject json = new JsonObject();

        json.updateString("test", "abc");

        try {
            json.newArrayOf("big_cats", big_cats);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        json.setEmitCompact(false);
        System.out.println(json.emit());

        // Result:

        // {
        //   "test": "abc",
        //   "big_cats": [
        //     "lion",
        //     "tiger",
        //     "leopard",
        //     "jaguar",
        //     "cheetah",
        //     "snow leopard",
        //     "clouded leopard",
        //     "cougar",
        //     "puma",
        //     "panther"
        //   ]
        // }
    }
}