playframework Java - Working with JSON Manual creating JSON


Example

import play.libs.Json;


public JsonNode createJson() {
    // {"id": 33, "values": [3, 4, 5]}
    ObjectNode rootNode = Json.newObject();
    ArrayNode listNode = Json.newArray();

    long values[] = {3, 4, 5};
    for (long val: values) {
        listNode.add(val);
    }
    
    rootNode.put("id", 33);
    rootNode.set("values", listNode);
    return rootNode;
}