- java.lang.Object
-
- at.syntaxerror.json5.JSONObject
-
-
Constructor Summary
Constructors Constructor Description JSONObject()Constructs a new JSONObjectJSONObject(JSONParser parser)Constructs a new JSONObject from a JSONParserJSONObject(String source)Constructs a new JSONObject from a string
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Removes all values from this JSONObjectJSONObjectcompute(String key, BiFunction<String,Object,Object> remappingFunction)Replaces or sets the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeArray(String key, BiFunction<String,JSONArray,Object> remappingFunction)Replaces or sets the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeArrayIfPresent(String key, BiFunction<String,JSONArray,Object> remappingFunction)Replaces the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeBoolean(String key, BiFunction<String,Boolean,Object> remappingFunction)Replaces or sets the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeBooleanIfPresent(String key, BiFunction<String,Boolean,Object> remappingFunction)Replaces the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeByte(String key, BiFunction<String,Byte,Object> remappingFunction)Replaces or sets the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeByteExact(String key, BiFunction<String,Byte,Object> remappingFunction)Replaces or sets the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeByteExactIfPresent(String key, BiFunction<String,Byte,Object> remappingFunction)Replaces the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeByteIfPresent(String key, BiFunction<String,Byte,Object> remappingFunction)Replaces the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeDouble(String key, BiFunction<String,Double,Object> remappingFunction)Replaces or sets the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeDoubleExact(String key, BiFunction<String,Double,Object> remappingFunction)Replaces or sets the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeDoubleExactIfPresent(String key, BiFunction<String,Double,Object> remappingFunction)Replaces the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeDoubleIfPresent(String key, BiFunction<String,Double,Object> remappingFunction)Replaces the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeFloat(String key, BiFunction<String,Float,Object> remappingFunction)Replaces or sets the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeFloatExact(String key, BiFunction<String,Float,Object> remappingFunction)Replaces or sets the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeFloatExactIfPresent(String key, BiFunction<String,Float,Object> remappingFunction)Replaces the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeFloatIfPresent(String key, BiFunction<String,Float,Object> remappingFunction)Replaces the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeIfAbsent(String key, Function<String,Object> mappingFunction)Associates the value returned by the mapping function with the given key if the key is not already associated with a value.JSONObjectcomputeIfPresent(String key, BiFunction<String,Object,Object> remappingFunction)Replaces the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeInstant(String key, BiFunction<String,Instant,Object> remappingFunction)Replaces or sets the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeInstantIfPresent(String key, BiFunction<String,Instant,Object> remappingFunction)Replaces the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeInt(String key, BiFunction<String,Integer,Object> remappingFunction)Replaces or sets the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeIntExact(String key, BiFunction<String,Integer,Object> remappingFunction)Replaces or sets the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeIntExactIfPresent(String key, BiFunction<String,Integer,Object> remappingFunction)Replaces the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeIntIfPresent(String key, BiFunction<String,Integer,Object> remappingFunction)Replaces the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeLong(String key, BiFunction<String,Long,Object> remappingFunction)Replaces or sets the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeLongExact(String key, BiFunction<String,Long,Object> remappingFunction)Replaces or sets the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeLongExactIfPresent(String key, BiFunction<String,Long,Object> remappingFunction)Replaces the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeLongIfPresent(String key, BiFunction<String,Long,Object> remappingFunction)Replaces the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeObject(String key, BiFunction<String,JSONObject,Object> remappingFunction)Replaces or sets the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeObjectIfPresent(String key, BiFunction<String,JSONObject,Object> remappingFunction)Replaces the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeShort(String key, BiFunction<String,Short,Object> remappingFunction)Replaces or sets the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeShortExact(String key, BiFunction<String,Short,Object> remappingFunction)Replaces or sets the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeShortExactIfPresent(String key, BiFunction<String,Short,Object> remappingFunction)Replaces the value associated with the given key with the value returned by the remapping function.JSONObjectcomputeShortIfPresent(String key, BiFunction<String,Short,Object> remappingFunction)Replaces the value associated with the given key with the value returned by the remapping function.JSONObjectcopy()Creates a shallow copy of the JSONObjectJSONObjectdeepCopy()Creates a deep copy of the JSONObjectSet<Map.Entry<String,Object>>entrySet()Returns a set of entries of the JSONObject.voidforEach(BiConsumer<String,Object> action)Iterates over the whole JSONObject and performs the given action for each element.Objectget(String key)Returns the value for a given keyObjectget(String key, Object defaults)Returns the value for a given key, or the default value if the operation is not possibleJSONArraygetArray(String key)Returns the value as a JSONArray for a given keyJSONArraygetArray(String key, JSONArray defaults)Returns the value as a JSONArray for a given key, or the default value if the operation is not possiblebooleangetBoolean(String key)Returns the value as a boolean for a given keybooleangetBoolean(String key, boolean defaults)Returns the value as a boolean for a given key, or the default value if the operation is not possiblebytegetByte(String key)Returns the value as a byte for a given keybytegetByte(String key, byte defaults)Returns the value as a byte for a given key, or the default value if the operation is not possiblebytegetByteExact(String key)Returns the exact value as a byte for a given key.bytegetByteExact(String key, byte defaults)Returns the exact value as a byte for a given key, or the default value if the operation is not possibledoublegetDouble(String key)Returns the value as a double for a given keydoublegetDouble(String key, double defaults)Returns the value as a double for a given key, or the default value if the operation is not possibledoublegetDoubleExact(String key)Returns the exact value as a double for a given key.doublegetDoubleExact(String key, double defaults)Returns the exact value as a double for a given key, or the default value if the operation is not possiblefloatgetFloat(String key)Returns the value as a float for a given keyfloatgetFloat(String key, float defaults)Returns the value as a float for a given key, or the default value if the operation is not possiblefloatgetFloatExact(String key)Returns the exact value as a float for a given key.floatgetFloatExact(String key, float defaults)Returns the exact value as a float for a given key, or the default value if the operation is not possibleInstantgetInstant(String key)Returns the value as an Instant for a given key.InstantgetInstant(String key, Instant defaults)Returns the value as an Instant for a given key, or the default value if the operation is not possibleintgetInt(String key)Returns the value as an int for a given keyintgetInt(String key, int defaults)Returns the value as an int for a given key, or the default value if the operation is not possibleintgetIntExact(String key)Returns the exact value as an int for a given key.intgetIntExact(String key, int defaults)Returns the exact value as an int for a given key, or the default value if the operation is not possiblelonggetLong(String key)Returns the value as a long for a given keylonggetLong(String key, long defaults)Returns the value as a long for a given key, or the default value if the operation is not possiblelonggetLongExact(String key)Returns the exact value as a long for a given key.longgetLongExact(String key, long defaults)Returns the exact value as a long for a given key, or the default value if the operation is not possibleNumbergetNumber(String key)Returns the value as a number for a given keyNumbergetNumber(String key, Number defaults)Returns the value as a number for a given key, or the default value if the operation is not possibleJSONObjectgetObject(String key)Returns the value as a JSONObject for a given keyJSONObjectgetObject(String key, JSONObject defaults)Returns the value as a JSONObject for a given key, or the default value if the operation is not possibleshortgetShort(String key)Returns the value as a short for a given keyshortgetShort(String key, short defaults)Returns the value as a short for a given key, or the default value if the operation is not possibleshortgetShortExact(String key)Returns the exact value as a short for a given key.shortgetShortExact(String key, short defaults)Returns the exact value as a short for a given key, or the default value if the operation is not possibleStringgetString(String key)Returns the value as a string for a given keyStringgetString(String key, String defaults)Returns the value as a string for a given key, or the default value if the operation is not possiblebooleanhas(String key)Checks if a key exists within the JSONObjectbooleanisArray(String key)Checks if the value with the specified key is a JSONArraybooleanisBoolean(String key)Checks if the value with the specified key is a booleanbooleanisInstant(String key)Checks if the value with the specified key can be converted to anInstant.booleanisNull(String key)Checks if the value with the specified key isnullbooleanisNumber(String key)Checks if the value with the specified key is a numberbooleanisObject(String key)Checks if the value with the specified key is a JSONObjectbooleanisString(String key)Checks if the value with the specified key is a stringIterator<Map.Entry<String,Object>>iterator()Set<String>keySet()Returns a set of keys of the JSONObject.intlength()Returns the number of entries in the JSONObjectstatic InstantparseInstant(Object value)Tries to convert an object to an Instant.JSONObjectputAll(JSONObject obj)Adds the values of the given JSONObject to this JSONObject.JSONObjectputAllDeep(JSONObject obj)Adds the values of the given JSONObject to this JSONObject.voidremove(String key)Removes a key from a JSONObjectJSONObjectremoveArrayIf(String key, Predicate<JSONArray> predicate)Removes a key from a JSONObject if the predicate returnstrue.JSONObjectremoveBooleanIf(String key, Predicate<Boolean> predicate)Removes a key from a JSONObject if the predicate returnstrue.JSONObjectremoveByteExactIf(String key, Predicate<Byte> predicate)Removes a key from a JSONObject if the predicate returnstrue.JSONObjectremoveByteIf(String key, Predicate<Byte> predicate)Removes a key from a JSONObject if the predicate returnstrue.JSONObjectremoveDoubleExactIf(String key, Predicate<Double> predicate)Removes a key from a JSONObject if the predicate returnstrue.JSONObjectremoveDoubleIf(String key, Predicate<Double> predicate)Removes a key from a JSONObject if the predicate returnstrue.JSONObjectremoveFloatExactIf(String key, Predicate<Float> predicate)Removes a key from a JSONObject if the predicate returnstrue.JSONObjectremoveFloatIf(String key, Predicate<Float> predicate)Removes a key from a JSONObject if the predicate returnstrue.JSONObjectremoveIf(String key, Predicate<Object> predicate)Removes a key from a JSONObject if the predicate returnstrue.JSONObjectremoveIf(BiPredicate<String,Object> predicate)Removes all entries from a JSONObject where the predicate returnstrue.JSONObjectremoveInstantIf(String key, Predicate<Instant> predicate)Removes a key from a JSONObject if the predicate returnstrue.JSONObjectremoveIntExactIf(String key, Predicate<Integer> predicate)Removes a key from a JSONObject if the predicate returnstrue.JSONObjectremoveIntIf(String key, Predicate<Integer> predicate)Removes a key from a JSONObject if the predicate returnstrue.JSONObjectremoveKeys(JSONObject obj)Removes all the keys if the same key exists within the other JSONObject too.JSONObjectremoveLongExactIf(String key, Predicate<Long> predicate)Removes a key from a JSONObject if the predicate returnstrue.JSONObjectremoveLongIf(String key, Predicate<Long> predicate)Removes a key from a JSONObject if the predicate returnstrue.JSONObjectremoveObjectIf(String key, Predicate<JSONObject> predicate)Removes a key from a JSONObject if the predicate returnstrue.JSONObjectremoveShortExactIf(String key, Predicate<Short> predicate)Removes a key from a JSONObject if the predicate returnstrue.JSONObjectremoveShortIf(String key, Predicate<Short> predicate)Removes a key from a JSONObject if the predicate returnstrue.JSONObjectretainArrayIf(String key, Predicate<JSONArray> predicate)Removes a key from a JSONObject if the predicate returnsfalse.JSONObjectretainBooleanIf(String key, Predicate<Boolean> predicate)Removes a key from a JSONObject if the predicate returnsfalse.JSONObjectretainByteExactIf(String key, Predicate<Byte> predicate)Removes a key from a JSONObject if the predicate returnsfalse.JSONObjectretainByteIf(String key, Predicate<Byte> predicate)Removes a key from a JSONObject if the predicate returnsfalse.JSONObjectretainDoubleExactIf(String key, Predicate<Double> predicate)Removes a key from a JSONObject if the predicate returnsfalse.JSONObjectretainDoubleIf(String key, Predicate<Double> predicate)Removes a key from a JSONObject if the predicate returnsfalse.JSONObjectretainFloatExactIf(String key, Predicate<Float> predicate)Removes a key from a JSONObject if the predicate returnsfalse.JSONObjectretainFloatIf(String key, Predicate<Float> predicate)Removes a key from a JSONObject if the predicate returnsfalse.JSONObjectretainIf(String key, Predicate<Object> predicate)Removes a key from a JSONObject if the predicate returnsfalse.JSONObjectretainIf(BiPredicate<String,Object> predicate)Removes all entries from a JSONObject where the predicate returnsfalse.JSONObjectretainInstantIf(String key, Predicate<Instant> predicate)Removes a key from a JSONObject if the predicate returnsfalse.JSONObjectretainIntExactIf(String key, Predicate<Integer> predicate)Removes a key from a JSONObject if the predicate returnsfalse.JSONObjectretainIntIf(String key, Predicate<Integer> predicate)Removes a key from a JSONObject if the predicate returnsfalse.JSONObjectretainKeys(JSONObject obj)Retains only the keys if the same key exists within the other JSONObject too.JSONObjectretainLongExactIf(String key, Predicate<Long> predicate)Removes a key from a JSONObject if the predicate returnsfalse.JSONObjectretainLongIf(String key, Predicate<Long> predicate)Removes a key from a JSONObject if the predicate returnsfalse.JSONObjectretainObjectIf(String key, Predicate<JSONObject> predicate)Removes a key from a JSONObject if the predicate returnsfalse.JSONObjectretainShortExactIf(String key, Predicate<Short> predicate)Removes a key from a JSONObject if the predicate returnsfalse.JSONObjectretainShortIf(String key, Predicate<Short> predicate)Removes a key from a JSONObject if the predicate returnsfalse.JSONObjectset(String key, Object value)Sets the value at a given keyJSONObjectsetIfAbsent(String key, Object value)Sets the value at a given key if there is no value associated with the key yetJSONObjectsetIfPresent(String key, Object value)Sets the value at a given key if there is already a value associated with the keyMap<String,Object>toMap()Converts the JSONObject into a map.StringtoString()Converts the JSONObject into its compact string representation.StringtoString(int indentFactor)Converts the JSONObject into its string representation.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
JSONObject
public JSONObject()
Constructs a new JSONObject
-
JSONObject
public JSONObject(String source)
Constructs a new JSONObject from a string- Parameters:
source- a string
-
JSONObject
public JSONObject(JSONParser parser)
Constructs a new JSONObject from a JSONParser- Parameters:
parser- a JSONParser
-
-
Method Detail
-
copy
public JSONObject copy()
Creates a shallow copy of the JSONObject- Returns:
- the new JSONObject
- Since:
- 2.0.0
-
deepCopy
public JSONObject deepCopy()
Creates a deep copy of the JSONObject- Returns:
- the new JSONObject
- Since:
- 2.0.0
-
toMap
public Map<String,Object> toMap()
Converts the JSONObject into a map. All JSONObjects and JSONArrays contained within this JSONObject will be converted into their Map or List form as well- Returns:
- a map of the entries of this object
-
keySet
public Set<String> keySet()
Returns a set of keys of the JSONObject. Modifying the set will modify the JSONObject- Returns:
- a set of keys
- See Also:
Map.keySet()
-
entrySet
public Set<Map.Entry<String,Object>> entrySet()
Returns a set of entries of the JSONObject. Modifying the set or an entry will modify the JSONObjectUse with caution. Inserting objects of unknown types may cause issues when trying to use the JSONObject
- Returns:
- a set of entries
- See Also:
Map.entrySet()
-
forEach
public void forEach(BiConsumer<String,Object> action)
Iterates over the whole JSONObject and performs the given action for each element.For each entry in the object, the predicate receives the key and its associated value.
- Parameters:
action- The action for each entry- Since:
- 2.0.0
-
length
public int length()
Returns the number of entries in the JSONObject- Returns:
- the number of entries
-
clear
public void clear()
Removes all values from this JSONObject- Since:
- 1.2.0
-
remove
public void remove(String key)
Removes a key from a JSONObject- Parameters:
key- the key to be removed- Throws:
JSONException- if the key does not exist- Since:
- 1.2.0
-
removeIf
public JSONObject removeIf(BiPredicate<String,Object> predicate)
Removes all entries from a JSONObject where the predicate returnstrue.For each entry in the object, the predicate receives the key and its associated value.
- Parameters:
predicate- the predicate- Returns:
- this JSONObject
- Since:
- 2.0.0
-
removeIf
public JSONObject removeIf(String key, Predicate<Object> predicate)
Removes a key from a JSONObject if the predicate returnstrue.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Since:
- 2.0.0
-
removeBooleanIf
public JSONObject removeBooleanIf(String key, Predicate<Boolean> predicate)
Removes a key from a JSONObject if the predicate returnstrue.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a boolean- Since:
- 2.0.0
-
removeByteIf
public JSONObject removeByteIf(String key, Predicate<Byte> predicate)
Removes a key from a JSONObject if the predicate returnstrue.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a byte- Since:
- 2.0.0
-
removeShortIf
public JSONObject removeShortIf(String key, Predicate<Short> predicate)
Removes a key from a JSONObject if the predicate returnstrue.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a short- Since:
- 2.0.0
-
removeIntIf
public JSONObject removeIntIf(String key, Predicate<Integer> predicate)
Removes a key from a JSONObject if the predicate returnstrue.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not an int- Since:
- 2.0.0
-
removeLongIf
public JSONObject removeLongIf(String key, Predicate<Long> predicate)
Removes a key from a JSONObject if the predicate returnstrue.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a long- Since:
- 2.0.0
-
removeFloatIf
public JSONObject removeFloatIf(String key, Predicate<Float> predicate)
Removes a key from a JSONObject if the predicate returnstrue.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a float- Since:
- 2.0.0
-
removeDoubleIf
public JSONObject removeDoubleIf(String key, Predicate<Double> predicate)
Removes a key from a JSONObject if the predicate returnstrue.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a double- Since:
- 2.0.0
-
removeByteExactIf
public JSONObject removeByteExactIf(String key, Predicate<Byte> predicate)
Removes a key from a JSONObject if the predicate returnstrue.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a byte, or if the value does not fit into a byte- Since:
- 2.0.0
-
removeShortExactIf
public JSONObject removeShortExactIf(String key, Predicate<Short> predicate)
Removes a key from a JSONObject if the predicate returnstrue.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a short, or if the value does not fit into a short- Since:
- 2.0.0
-
removeIntExactIf
public JSONObject removeIntExactIf(String key, Predicate<Integer> predicate)
Removes a key from a JSONObject if the predicate returnstrue.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not an int, or if the value does not fit into an int- Since:
- 2.0.0
-
removeLongExactIf
public JSONObject removeLongExactIf(String key, Predicate<Long> predicate)
Removes a key from a JSONObject if the predicate returnstrue.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a long, or if the value does not fit into a long- Since:
- 2.0.0
-
removeFloatExactIf
public JSONObject removeFloatExactIf(String key, Predicate<Float> predicate)
Removes a key from a JSONObject if the predicate returnstrue.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a float, or if the value does not fit into a float- Since:
- 2.0.0
-
removeDoubleExactIf
public JSONObject removeDoubleExactIf(String key, Predicate<Double> predicate)
Removes a key from a JSONObject if the predicate returnstrue.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a double, or if the value does not fit into a double- Since:
- 2.0.0
-
removeObjectIf
public JSONObject removeObjectIf(String key, Predicate<JSONObject> predicate)
Removes a key from a JSONObject if the predicate returnstrue.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a JSONObject- Since:
- 2.0.0
-
removeArrayIf
public JSONObject removeArrayIf(String key, Predicate<JSONArray> predicate)
Removes a key from a JSONObject if the predicate returnstrue.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a JSONArray- Since:
- 2.0.0
-
removeInstantIf
public JSONObject removeInstantIf(String key, Predicate<Instant> predicate)
Removes a key from a JSONObject if the predicate returnstrue.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not an instant- Since:
- 2.0.0
-
removeKeys
public JSONObject removeKeys(JSONObject obj)
Removes all the keys if the same key exists within the other JSONObject too.This does not compare the values.
- Parameters:
obj- the other JSONObject- Returns:
- this JSONObject
- Since:
- 2.0.0
-
retainIf
public JSONObject retainIf(BiPredicate<String,Object> predicate)
Removes all entries from a JSONObject where the predicate returnsfalse.For each entry in the object, the predicate receives the key and its associated value.
- Parameters:
predicate- the predicate- Returns:
- this JSONObject
- Since:
- 2.0.0
-
retainIf
public JSONObject retainIf(String key, Predicate<Object> predicate)
Removes a key from a JSONObject if the predicate returnsfalse.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Since:
- 2.0.0
-
retainBooleanIf
public JSONObject retainBooleanIf(String key, Predicate<Boolean> predicate)
Removes a key from a JSONObject if the predicate returnsfalse.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a boolean- Since:
- 2.0.0
-
retainByteIf
public JSONObject retainByteIf(String key, Predicate<Byte> predicate)
Removes a key from a JSONObject if the predicate returnsfalse.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a byte- Since:
- 2.0.0
-
retainShortIf
public JSONObject retainShortIf(String key, Predicate<Short> predicate)
Removes a key from a JSONObject if the predicate returnsfalse.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a short- Since:
- 2.0.0
-
retainIntIf
public JSONObject retainIntIf(String key, Predicate<Integer> predicate)
Removes a key from a JSONObject if the predicate returnsfalse.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not an int- Since:
- 2.0.0
-
retainLongIf
public JSONObject retainLongIf(String key, Predicate<Long> predicate)
Removes a key from a JSONObject if the predicate returnsfalse.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a long- Since:
- 2.0.0
-
retainFloatIf
public JSONObject retainFloatIf(String key, Predicate<Float> predicate)
Removes a key from a JSONObject if the predicate returnsfalse.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a float- Since:
- 2.0.0
-
retainDoubleIf
public JSONObject retainDoubleIf(String key, Predicate<Double> predicate)
Removes a key from a JSONObject if the predicate returnsfalse.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a double- Since:
- 2.0.0
-
retainByteExactIf
public JSONObject retainByteExactIf(String key, Predicate<Byte> predicate)
Removes a key from a JSONObject if the predicate returnsfalse.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a byte, or if the value does not fit into a byte- Since:
- 2.0.0
-
retainShortExactIf
public JSONObject retainShortExactIf(String key, Predicate<Short> predicate)
Removes a key from a JSONObject if the predicate returnsfalse.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a short, or if the value does not fit into a short- Since:
- 2.0.0
-
retainIntExactIf
public JSONObject retainIntExactIf(String key, Predicate<Integer> predicate)
Removes a key from a JSONObject if the predicate returnsfalse.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not an int, or if the value does not fit into an int- Since:
- 2.0.0
-
retainLongExactIf
public JSONObject retainLongExactIf(String key, Predicate<Long> predicate)
Removes a key from a JSONObject if the predicate returnsfalse.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a long, or if the value does not fit into a long- Since:
- 2.0.0
-
retainFloatExactIf
public JSONObject retainFloatExactIf(String key, Predicate<Float> predicate)
Removes a key from a JSONObject if the predicate returnsfalse.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a float, or if the value does not fit into a float- Since:
- 2.0.0
-
retainDoubleExactIf
public JSONObject retainDoubleExactIf(String key, Predicate<Double> predicate)
Removes a key from a JSONObject if the predicate returnsfalse.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a double, or if the value does not fit into a double- Since:
- 2.0.0
-
retainObjectIf
public JSONObject retainObjectIf(String key, Predicate<JSONObject> predicate)
Removes a key from a JSONObject if the predicate returnsfalse.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a JSONObject- Since:
- 2.0.0
-
retainArrayIf
public JSONObject retainArrayIf(String key, Predicate<JSONArray> predicate)
Removes a key from a JSONObject if the predicate returnsfalse.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a JSONArray- Since:
- 2.0.0
-
retainInstantIf
public JSONObject retainInstantIf(String key, Predicate<Instant> predicate)
Removes a key from a JSONObject if the predicate returnsfalse.- Parameters:
key- the keypredicate- the predicate- Returns:
- this JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not an instant- Since:
- 2.0.0
-
retainKeys
public JSONObject retainKeys(JSONObject obj)
Retains only the keys if the same key exists within the other JSONObject too.This does not compare the values.
- Parameters:
obj- the other JSONObject- Returns:
- this JSONObject
- Since:
- 2.0.0
-
has
public boolean has(String key)
Checks if a key exists within the JSONObject- Parameters:
key- the key- Returns:
- whether the key exists
-
isNull
public boolean isNull(String key)
Checks if the value with the specified key isnull- Parameters:
key- the key- Returns:
- whether the value is
null - Throws:
JSONException- if the key does not exist
-
isBoolean
public boolean isBoolean(String key)
Checks if the value with the specified key is a boolean- Parameters:
key- the key- Returns:
- whether the value is a boolean
- Throws:
JSONException- if the key does not exist
-
isString
public boolean isString(String key)
Checks if the value with the specified key is a string- Parameters:
key- the key- Returns:
- whether the value is a string
- Throws:
JSONException- if the key does not exist
-
isNumber
public boolean isNumber(String key)
Checks if the value with the specified key is a number- Parameters:
key- the key- Returns:
- whether the value is a number
- Throws:
JSONException- if the key does not exist
-
isObject
public boolean isObject(String key)
Checks if the value with the specified key is a JSONObject- Parameters:
key- the key- Returns:
- whether the value is a JSONObject
- Throws:
JSONException- if the key does not exist
-
isArray
public boolean isArray(String key)
Checks if the value with the specified key is a JSONArray- Parameters:
key- the key- Returns:
- whether the value is a JSONArray
- Throws:
JSONException- if the key does not exist
-
isInstant
public boolean isInstant(String key)
Checks if the value with the specified key can be converted to anInstant.- Parameters:
key- the key- Returns:
- whether the value is an Instant
- Throws:
JSONException- if the key does not exist- Since:
- 1.1.0
- See Also:
parseInstant(Object)
-
get
public Object get(String key)
Returns the value for a given key- Parameters:
key- the key- Returns:
- the value
- Throws:
JSONException- if the key does not exist
-
getBoolean
public boolean getBoolean(String key)
Returns the value as a boolean for a given key- Parameters:
key- the key- Returns:
- the boolean
- Throws:
JSONException- if the key does not exist, or if the value is not a boolean
-
getString
public String getString(String key)
Returns the value as a string for a given key- Parameters:
key- the key- Returns:
- the string
- Throws:
JSONException- if the key does not exist, or if the value is not a string
-
getNumber
public Number getNumber(String key)
Returns the value as a number for a given key- Parameters:
key- the key- Returns:
- the number
- Throws:
JSONException- if the key does not exist, or if the value is not a number
-
getByte
public byte getByte(String key)
Returns the value as a byte for a given key- Parameters:
key- the key- Returns:
- the byte
- Throws:
JSONException- if the key does not exist, or if the value is not a byte
-
getShort
public short getShort(String key)
Returns the value as a short for a given key- Parameters:
key- the key- Returns:
- the short
- Throws:
JSONException- if the key does not exist, or if the value is not a short
-
getInt
public int getInt(String key)
Returns the value as an int for a given key- Parameters:
key- the key- Returns:
- the int
- Throws:
JSONException- if the key does not exist, or if the value is not an int
-
getLong
public long getLong(String key)
Returns the value as a long for a given key- Parameters:
key- the key- Returns:
- the long
- Throws:
JSONException- if the key does not exist, or if the value is not a long
-
getFloat
public float getFloat(String key)
Returns the value as a float for a given key- Parameters:
key- the key- Returns:
- the float
- Throws:
JSONException- if the key does not exist, or if the value is not a float
-
getDouble
public double getDouble(String key)
Returns the value as a double for a given key- Parameters:
key- the key- Returns:
- the double
- Throws:
JSONException- if the key does not exist, or if the value is not a double
-
getByteExact
public byte getByteExact(String key)
Returns the exact value as a byte for a given key. This fails if the value does not fit into a byte- Parameters:
key- the key- Returns:
- the byte
- Throws:
JSONException- if the key does not exist, the value is not a byte, or if the value does not fit into a byte
-
getShortExact
public short getShortExact(String key)
Returns the exact value as a short for a given key. This fails if the value does not fit into a short- Parameters:
key- the key- Returns:
- the short
- Throws:
JSONException- if the key does not exist, the value is not a short, or if the value does not fit into a short
-
getIntExact
public int getIntExact(String key)
Returns the exact value as an int for a given key. This fails if the value does not fit into an int- Parameters:
key- the key- Returns:
- the int
- Throws:
JSONException- if the key does not exist, the value is not an int, or if the value does not fit into an int
-
getLongExact
public long getLongExact(String key)
Returns the exact value as a long for a given key. This fails if the value does not fit into a long- Parameters:
key- the key- Returns:
- the long
- Throws:
JSONException- if the key does not exist, the value is not a long, or if the value does not fit into a long
-
getFloatExact
public float getFloatExact(String key)
Returns the exact value as a float for a given key. This fails if the value does not fit into a float- Parameters:
key- the key- Returns:
- the float
- Throws:
JSONException- if the key does not exist, the value is not a float, or if the value does not fit into a float
-
getDoubleExact
public double getDoubleExact(String key)
Returns the exact value as a double for a given key. This fails if the value does not fit into a double- Parameters:
key- the key- Returns:
- the double
- Throws:
JSONException- if the key does not exist, the value is not a double, or if the value does not fit into a double
-
getObject
public JSONObject getObject(String key)
Returns the value as a JSONObject for a given key- Parameters:
key- the key- Returns:
- the JSONObject
- Throws:
JSONException- if the key does not exist, or if the value is not a JSONObject
-
getArray
public JSONArray getArray(String key)
Returns the value as a JSONArray for a given key- Parameters:
key- the key- Returns:
- the JSONArray
- Throws:
JSONException- if the key does not exist, or if the value is not a JSONArray
-
getInstant
public Instant getInstant(String key)
Returns the value as an Instant for a given key.- Parameters:
key- the key- Returns:
- the Instant
- Throws:
JSONException- if the key does not exist, or if the value is not an Instant- Since:
- 1.1.0
- See Also:
parseInstant(Object)
-
get
public Object get(String key, Object defaults)
Returns the value for a given key, or the default value if the operation is not possible- Parameters:
key- the keydefaults- the default value- Returns:
- the value
-
getBoolean
public boolean getBoolean(String key, boolean defaults)
Returns the value as a boolean for a given key, or the default value if the operation is not possible- Parameters:
key- the keydefaults- the default value- Returns:
- the boolean
-
getString
public String getString(String key, String defaults)
Returns the value as a string for a given key, or the default value if the operation is not possible- Parameters:
key- the keydefaults- the default value- Returns:
- the string
-
getNumber
public Number getNumber(String key, Number defaults)
Returns the value as a number for a given key, or the default value if the operation is not possible- Parameters:
key- the keydefaults- the default value- Returns:
- the number
-
getByte
public byte getByte(String key, byte defaults)
Returns the value as a byte for a given key, or the default value if the operation is not possible- Parameters:
key- the keydefaults- the default value- Returns:
- the byte
-
getShort
public short getShort(String key, short defaults)
Returns the value as a short for a given key, or the default value if the operation is not possible- Parameters:
key- the keydefaults- the default value- Returns:
- the short
-
getInt
public int getInt(String key, int defaults)
Returns the value as an int for a given key, or the default value if the operation is not possible- Parameters:
key- the keydefaults- the default value- Returns:
- the int
-
getLong
public long getLong(String key, long defaults)
Returns the value as a long for a given key, or the default value if the operation is not possible- Parameters:
key- the keydefaults- the default value- Returns:
- the long
-
getFloat
public float getFloat(String key, float defaults)
Returns the value as a float for a given key, or the default value if the operation is not possible- Parameters:
key- the keydefaults- the default value- Returns:
- the float
-
getDouble
public double getDouble(String key, double defaults)
Returns the value as a double for a given key, or the default value if the operation is not possible- Parameters:
key- the keydefaults- the default value- Returns:
- the double
-
getByteExact
public byte getByteExact(String key, byte defaults)
Returns the exact value as a byte for a given key, or the default value if the operation is not possible- Parameters:
key- the keydefaults- the default value- Returns:
- the byte
-
getShortExact
public short getShortExact(String key, short defaults)
Returns the exact value as a short for a given key, or the default value if the operation is not possible- Parameters:
key- the keydefaults- the default value- Returns:
- the short
-
getIntExact
public int getIntExact(String key, int defaults)
Returns the exact value as an int for a given key, or the default value if the operation is not possible- Parameters:
key- the keydefaults- the default value- Returns:
- the int
-
getLongExact
public long getLongExact(String key, long defaults)
Returns the exact value as a long for a given key, or the default value if the operation is not possible- Parameters:
key- the keydefaults- the default value- Returns:
- the long
-
getFloatExact
public float getFloatExact(String key, float defaults)
Returns the exact value as a float for a given key, or the default value if the operation is not possible- Parameters:
key- the keydefaults- the default value- Returns:
- the float
-
getDoubleExact
public double getDoubleExact(String key, double defaults)
Returns the exact value as a double for a given key, or the default value if the operation is not possible- Parameters:
key- the keydefaults- the default value- Returns:
- the double
-
getObject
public JSONObject getObject(String key, JSONObject defaults)
Returns the value as a JSONObject for a given key, or the default value if the operation is not possible- Parameters:
key- the keydefaults- the default value- Returns:
- the JSONObject
-
getArray
public JSONArray getArray(String key, JSONArray defaults)
Returns the value as a JSONArray for a given key, or the default value if the operation is not possible- Parameters:
key- the keydefaults- the default value- Returns:
- the JSONArray
-
getInstant
public Instant getInstant(String key, Instant defaults)
Returns the value as an Instant for a given key, or the default value if the operation is not possible- Parameters:
key- the keydefaults- the default value- Returns:
- the Instant
- Since:
- 1.1.0
-
putAll
public JSONObject putAll(JSONObject obj)
Adds the values of the given JSONObject to this JSONObject. Afterwards, changes in nested JSONObjects or JSONArrays of one object are reflected in the other object too.This effectively shallow copies one JSONObject into another.
- Parameters:
obj- the other JSONObject- Returns:
- this JSONObject
- Since:
- 2.0.0
-
putAllDeep
public JSONObject putAllDeep(JSONObject obj)
Adds the values of the given JSONObject to this JSONObject. For all nested JSONObjects and JSONArrays,deep copiesare created. Afterwards, changes in nested JSONObjects or JSONArrays of one object are not reflected in the other object.This effectively deep copies one JSONObject into another.
- Parameters:
obj- the other JSONObject- Returns:
- this JSONObject
- Since:
- 2.0.0
-
set
public JSONObject set(String key, Object value)
Sets the value at a given key- Parameters:
key- the keyvalue- the new value- Returns:
- this JSONObject
-
setIfAbsent
public JSONObject setIfAbsent(String key, Object value)
Sets the value at a given key if there is no value associated with the key yet- Parameters:
key- the keyvalue- the new value- Returns:
- this JSONObject
- Since:
- 2.0.0
-
setIfPresent
public JSONObject setIfPresent(String key, Object value)
Sets the value at a given key if there is already a value associated with the key- Parameters:
key- the keyvalue- the new value- Returns:
- this JSONObject
- Since:
- 2.0.0
-
compute
public JSONObject compute(String key, BiFunction<String,Object,Object> remappingFunction)
Replaces or sets the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value, or
nullif there is currently no value associated with the key.- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Since:
- 2.0.0
-
computeBoolean
public JSONObject computeBoolean(String key, BiFunction<String,Boolean,Object> remappingFunction)
Replaces or sets the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a boolean, or
nullif there is currently no value associated with the key.- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a boolean- Since:
- 2.0.0
-
computeByte
public JSONObject computeByte(String key, BiFunction<String,Byte,Object> remappingFunction)
Replaces or sets the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a byte, or
nullif there is currently no value associated with the key.- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a byte- Since:
- 2.0.0
-
computeShort
public JSONObject computeShort(String key, BiFunction<String,Short,Object> remappingFunction)
Replaces or sets the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a short, or
nullif there is currently no value associated with the key.- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a short- Since:
- 2.0.0
-
computeInt
public JSONObject computeInt(String key, BiFunction<String,Integer,Object> remappingFunction)
Replaces or sets the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as an int, or
nullif there is currently no value associated with the key.- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not an int- Since:
- 2.0.0
-
computeLong
public JSONObject computeLong(String key, BiFunction<String,Long,Object> remappingFunction)
Replaces or sets the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a long, or
nullif there is currently no value associated with the key.- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a long- Since:
- 2.0.0
-
computeFloat
public JSONObject computeFloat(String key, BiFunction<String,Float,Object> remappingFunction)
Replaces or sets the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a float, or
nullif there is currently no value associated with the key.- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a float- Since:
- 2.0.0
-
computeDouble
public JSONObject computeDouble(String key, BiFunction<String,Double,Object> remappingFunction)
Replaces or sets the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a double, or
nullif there is currently no value associated with the key.- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a double- Since:
- 2.0.0
-
computeByteExact
public JSONObject computeByteExact(String key, BiFunction<String,Byte,Object> remappingFunction)
Replaces or sets the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a byte (exact value), or
nullif there is currently no value associated with the key.- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a byte, or if the value does not fit into a byte- Since:
- 2.0.0
-
computeShortExact
public JSONObject computeShortExact(String key, BiFunction<String,Short,Object> remappingFunction)
Replaces or sets the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a short (exact value), or
nullif there is currently no value associated with the key.- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a short, or if the value does not fit into a short- Since:
- 2.0.0
-
computeIntExact
public JSONObject computeIntExact(String key, BiFunction<String,Integer,Object> remappingFunction)
Replaces or sets the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as an int (exact value), or
nullif there is currently no value associated with the key.- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not an int, or if the value does not fit into an int- Since:
- 2.0.0
-
computeLongExact
public JSONObject computeLongExact(String key, BiFunction<String,Long,Object> remappingFunction)
Replaces or sets the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a long (exact value), or
nullif there is currently no value associated with the key.- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a long, or if the value does not fit into a long- Since:
- 2.0.0
-
computeFloatExact
public JSONObject computeFloatExact(String key, BiFunction<String,Float,Object> remappingFunction)
Replaces or sets the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a float (exact value), or
nullif there is currently no value associated with the key.- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a float, or if the value does not fit into a float- Since:
- 2.0.0
-
computeDoubleExact
public JSONObject computeDoubleExact(String key, BiFunction<String,Double,Object> remappingFunction)
Replaces or sets the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a double (exact value), or
nullif there is currently no value associated with the key.- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a double, or if the value does not fit into a double- Since:
- 2.0.0
-
computeObject
public JSONObject computeObject(String key, BiFunction<String,JSONObject,Object> remappingFunction)
Replaces or sets the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a JSONObject, or
nullif there is currently no value associated with the key.- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a JSONObject- Since:
- 2.0.0
-
computeArray
public JSONObject computeArray(String key, BiFunction<String,JSONArray,Object> remappingFunction)
Replaces or sets the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a JSONArray, or
nullif there is currently no value associated with the key.- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a JSONArray- Since:
- 2.0.0
-
computeInstant
public JSONObject computeInstant(String key, BiFunction<String,Instant,Object> remappingFunction)
Replaces or sets the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as an instant, or
nullif there is currently no value associated with the key.- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not an instant- Since:
- 2.0.0
-
computeIfPresent
public JSONObject computeIfPresent(String key, BiFunction<String,Object,Object> remappingFunction)
Replaces the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value.
- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Since:
- 2.0.0
-
computeBooleanIfPresent
public JSONObject computeBooleanIfPresent(String key, BiFunction<String,Boolean,Object> remappingFunction)
Replaces the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a boolean.
- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a boolean- Since:
- 2.0.0
-
computeByteIfPresent
public JSONObject computeByteIfPresent(String key, BiFunction<String,Byte,Object> remappingFunction)
Replaces the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a byte.
- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a byte- Since:
- 2.0.0
-
computeShortIfPresent
public JSONObject computeShortIfPresent(String key, BiFunction<String,Short,Object> remappingFunction)
Replaces the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a short.
- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a short- Since:
- 2.0.0
-
computeIntIfPresent
public JSONObject computeIntIfPresent(String key, BiFunction<String,Integer,Object> remappingFunction)
Replaces the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as an int.
- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not an int- Since:
- 2.0.0
-
computeLongIfPresent
public JSONObject computeLongIfPresent(String key, BiFunction<String,Long,Object> remappingFunction)
Replaces the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a long.
- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a long- Since:
- 2.0.0
-
computeFloatIfPresent
public JSONObject computeFloatIfPresent(String key, BiFunction<String,Float,Object> remappingFunction)
Replaces the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a float.
- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a float- Since:
- 2.0.0
-
computeDoubleIfPresent
public JSONObject computeDoubleIfPresent(String key, BiFunction<String,Double,Object> remappingFunction)
Replaces the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a double.
- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a double- Since:
- 2.0.0
-
computeByteExactIfPresent
public JSONObject computeByteExactIfPresent(String key, BiFunction<String,Byte,Object> remappingFunction)
Replaces the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a byte (exact value).
- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a byte, or if the value does not fit into a byte- Since:
- 2.0.0
-
computeShortExactIfPresent
public JSONObject computeShortExactIfPresent(String key, BiFunction<String,Short,Object> remappingFunction)
Replaces the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a short (exact value).
- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a short, or if the value does not fit into a short- Since:
- 2.0.0
-
computeIntExactIfPresent
public JSONObject computeIntExactIfPresent(String key, BiFunction<String,Integer,Object> remappingFunction)
Replaces the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as an int (exact value).
- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not an int, or if the value does not fit into an int- Since:
- 2.0.0
-
computeLongExactIfPresent
public JSONObject computeLongExactIfPresent(String key, BiFunction<String,Long,Object> remappingFunction)
Replaces the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a long (exact value).
- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a long, or if the value does not fit into a long- Since:
- 2.0.0
-
computeFloatExactIfPresent
public JSONObject computeFloatExactIfPresent(String key, BiFunction<String,Float,Object> remappingFunction)
Replaces the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a float (exact value).
- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a float, or if the value does not fit into a float- Since:
- 2.0.0
-
computeDoubleExactIfPresent
public JSONObject computeDoubleExactIfPresent(String key, BiFunction<String,Double,Object> remappingFunction)
Replaces the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a double (exact value).
- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a double, or if the value does not fit into a double- Since:
- 2.0.0
-
computeObjectIfPresent
public JSONObject computeObjectIfPresent(String key, BiFunction<String,JSONObject,Object> remappingFunction)
Replaces the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a JSONObject.
- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a JSONObject- Since:
- 2.0.0
-
computeArrayIfPresent
public JSONObject computeArrayIfPresent(String key, BiFunction<String,JSONArray,Object> remappingFunction)
Replaces the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as a JSONArray.
- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not a JSONArray- Since:
- 2.0.0
-
computeInstantIfPresent
public JSONObject computeInstantIfPresent(String key, BiFunction<String,Instant,Object> remappingFunction)
Replaces the value associated with the given key with the value returned by the remapping function.The remapping function receives the key and its associated value as an instant.
- Parameters:
key- the keyremappingFunction- the remapping function- Returns:
- this JSONObject
- Throws:
JSONException- if the value is not an instant- Since:
- 2.0.0
-
computeIfAbsent
public JSONObject computeIfAbsent(String key, Function<String,Object> mappingFunction)
Associates the value returned by the mapping function with the given key if the key is not already associated with a value.The mapping function receives the key.
- Parameters:
key- the keymappingFunction- the mapping function- Returns:
- this JSONObject
- Since:
- 2.0.0
-
toString
public String toString(int indentFactor)
Converts the JSONObject into its string representation. The indentation factor enables pretty-printing and defines how many spaces (' ') should be placed before each key/value pair. A factor of< 1disables pretty-printing and discards any optional whitespace characters.indentFactor = 2:{ "key0": "value0", "key1": { "nested": 123 }, "key2": false }indentFactor = 0:{"key0":"value0","key1":{"nested":123},"key2":false}- Parameters:
indentFactor- the indentation factor- Returns:
- the string representation
- See Also:
JSONStringify.toString(JSONObject, int)
-
toString
public String toString()
Converts the JSONObject into its compact string representation.
-
parseInstant
public static Instant parseInstant(Object value)
Tries to convert an object to an Instant.In order for the conversion to succeed, the value must be either
- an
Instant, - a String formatted according to RFC 3339, Section 5.6, or
- an integer (primitive type or
BigInteger) that does not exceed the limits ofInstant.ofEpochSecond(long)
- Parameters:
value- the value- Returns:
- the parsed Instant
- Throws:
DateTimeException- if the value is malformed or out of rangeJSONException- if the value has an invalid type- See Also:
isInstant(String)
- an
-
-