Immutable and Mutable

All instances of JSONValue that correspond to JSON primitive values (null, boolean, string and number) are immutable. In other words, instances of JSONValueNull, JSONValueBoolean, JSONValueString and JSONValueNumber are immutable. Multiple threads can safely access those instance at a time.

On the other hands, the structure types (array and object) have immutable and mutable versions. JSONValueArray and JSONValueObject are abstract classes. The actual implementations of these abstract classes are JSONValueArrayImmutable, JSONValueArrayMutable, JSONValueObjectImmutable and JSONValueObjectMutable.

Invocation of any method that may change the contents (e.g. add() and put()) result in UnsupportedOperationException if it is immutable.

Parser

parse() and its varaitns always result in an immutable instance.

Conversion

You can get a mutable copy of an immutable JSON object or array with following methods:

Below are reverse methods:

These methods turn inner JSON objects and arrays to immutable or mutable, too. For example, if there is a mutable JSON object which contains two mutable JSON arrays, JSONValueObjectImmutable#toMutable() turns the given JSON object and two inner JSON arrays to immutable.