Represents a JSON object. A JSON object contains a sequence of members, which are pairs of a name and a JSON value (see {@link JsonValue}). Although JSON objects should be used for unordered collections, this class stores members in document order.
Members can be added using one of the add(name, value)
methods. Accepted values are either instances of {@link JsonValue}, strings, primitive numbers, or boolean values. To override values in an object, the set(name, value)
methods can be used. However, not that the add
methods perform better than set
.
Members can be accessed by their name using {@link #get(String)}. A list of all names can be obtained from the method {@link #names()}. This class also supports iterating over the members in document order using an {@link #iterator()} or an enhanced for loop:
for( Member member : jsonObject ) { String name = member.getName(); JsonValue value = member.getValue(); ... }
Note that this class is not thread-safe. If multiple threads access a JsonObject
instance concurrently, while at least one of these threads modifies the contents of this object, access to the instance must be synchronized externally. Failure to do so may lead to an inconsistent state.
This class is not supposed to be extended by clients.