Represents a JSON object, i.e. an unordered set of name/value pairs, where the names are strings and the values are JSON values.
Members can be added using the add(String, ...)
methods which accept instances of {@link JsonValue}, strings, primitive numbers, and boolean values. To modify certain values of an object, use the set(String, ...)
methods. Please note that the add
methods are faster than set
as they do not search for existing members. On the other hand, the add
methods do not prevent adding multiple members with the same name. Duplicate names are discouraged but not prohibited by JSON.
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(); ... }
Even though JSON objects are unordered by definition, instances of this class preserve the order of members to allow processing in document order and to guarantee a predictable output.
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.