JSON Processing (JSON-P) - Home

JSON-P Object Model calls

public static void main(String[] args) {
   // Create Json and serialize
   JsonObject json = Json.createObjectBuilder()
     .add("name", "Falco")
     .add("age", BigDecimal.valueOf(3))
     .add("biteable", Boolean.FALSE).build();
   String result = json.toString();
     
   System.out.println(result);
 }

JSON-P Streaming API calls

public static void main(String[] args) {
    // Parse back
    final String result = "{\"name\":\"Falco\",\"age\":3,\"bitable\":false}";
    final JsonParser parser = Json.createParser(new StringReader(result));
    String key = null;
    String value = null;
    while (parser.hasNext()) {
        final Event event = parser.next();
        switch (event) {
        case KEY_NAME:
            key = parser.getString();
            System.out.println(key);
            break;
        case VALUE_STRING:
            value = parser.getString();
            System.out.println(value);
            break;
        }
    }
    parser.close();
}

The JSON representation

{
    "name": "Falco",
    "age": 3,
    "bitable": false
}