Module jakarta.json
Package jakarta.json

Interface JsonArrayBuilder


public interface JsonArrayBuilder
A builder for creating JsonArray models from scratch, and for modifying a existing JsonArray.

A JsonArrayBuilder can start with an empty or a non-empty JSON array model. This interface provides methods to add, insert, remove and replace values in the JSON array model.

Methods in this class can be chained to perform multiple values to the array.

The class Json contains methods to create the builder object. The example code below shows how to build an empty JsonArray instance.

 
 JsonArray array = Json.createArrayBuilder().build();
 
 

The class JsonBuilderFactory also contains methods to create JsonArrayBuilder instances. A factory instance can be used to create multiple builder instances with the same configuration. This the preferred way to create multiple instances. The example code below shows how to build a JsonArray object that represents the following JSON array:

 
 [
     { "type": "home", "number": "212 555-1234" },
     { "type": "fax", "number": "646 555-4567" }
 ]
 
 

The following code creates the JSON array above:

 
 JsonBuilderFactory factory = Json.createBuilderFactory(config);
 JsonArray value = factory.createArrayBuilder()
     .add(factory.createObjectBuilder()
         .add("type", "home")
         .add("number", "212 555-1234"))
     .add(factory.createObjectBuilder()
         .add("type", "fax")
         .add("number", "646 555-4567"))
     .build();
 
 

This class does not allow null to be used as a value while building the JSON array

See Also: