-
- All Implemented Interfaces:
public final class JSONKt
-
-
Method Summary
Modifier and Type Method Description final static Map<String, Object>toMap(JSONObject $self)Unwraps recursively the JSONObject to a Map. final static List<Object>toList(JSONArray $self)Unwraps recursively the JSONArray to a List. final static UnitputIfNotEmpty(JSONObject $self, String name, JSONObject jsonObject)Maps name to jsonObject, clobbering any existing name/value mapping with the same name. final static UnitputIfNotEmpty(JSONObject $self, String name, JSONArray jsonArray)Maps name to jsonArray, clobbering any existing name/value mapping with the same name. final static UnitputIfNotEmpty(JSONObject $self, String name, JSONable jsonable)Maps name to jsonable after converting it to a JSONObject, clobbering any existing name/value mapping with the same name. final static IntegeroptPositiveInt(JSONObject $self, String name, Integer fallback, Boolean remove)Returns the value mapped by name if it exists and is a positive integer or can be coerced to a positive integer, or fallback otherwise. final static DoubleoptPositiveDouble(JSONObject $self, String name, Double fallback, Boolean remove)Returns the value mapped by name if it exists and is a positive double or can be coerced to a positive double, or fallback otherwise. final static StringoptNullableString(JSONObject $self, String name, Boolean remove)Returns the value mapped by name if it exists, or nullif no such mapping exists, it is not a string or it is empty.final static BooleanoptNullableBoolean(JSONObject $self, String name, Boolean remove)Returns the value mapped by name if it exists, coercing it if necessary, or nullif no such mapping exists.final static IntegeroptNullableInt(JSONObject $self, String name, Boolean remove)Returns the value mapped by name if it exists, coercing it if necessary, or nullif no such mapping exists.final static LongoptNullableLong(JSONObject $self, String name, Boolean remove)Returns the value mapped by name if it exists, coercing it if necessary, or nullif no such mapping exists.final static DoubleoptNullableDouble(JSONObject $self, String name, Boolean remove)Returns the value mapped by name if it exists, coercing it if necessary, or nullif no such mapping exists.final static List<String>optStringsFromArrayOrSingle(JSONObject $self, String name, Boolean remove)Returns the value mapped by name if it exists and is either a JSONArray of String or a single String value, or an empty list otherwise. final static <T extends Any> List<T>mapNotNull(JSONObject $self, Function1<Pair<String, Object>, T> transform)Returns a list containing the results of applying the given transform function to each element in the original JSONObject. final static <T extends Any> List<T>mapNotNull(JSONArray $self, Function1<Object, T> transform)Returns a list containing the results of applying the given transform function to each element in the original JSONArray. -
-
Method Detail
-
toMap
final static Map<String, Object> toMap(JSONObject $self)
Unwraps recursively the JSONObject to a Map.
-
toList
final static List<Object> toList(JSONArray $self)
Unwraps recursively the JSONArray to a List.
-
putIfNotEmpty
final static Unit putIfNotEmpty(JSONObject $self, String name, JSONObject jsonObject)
Maps name to jsonObject, clobbering any existing name/value mapping with the same name. If the JSONObject is empty, any existing mapping for name is removed.
-
putIfNotEmpty
final static Unit putIfNotEmpty(JSONObject $self, String name, JSONArray jsonArray)
Maps name to jsonArray, clobbering any existing name/value mapping with the same name. If the JSONArray is empty, any existing mapping for name is removed.
-
putIfNotEmpty
final static Unit putIfNotEmpty(JSONObject $self, String name, JSONable jsonable)
Maps name to jsonable after converting it to a JSONObject, clobbering any existing name/value mapping with the same name. If the JSONObject argument is empty, any existing mapping for name is removed.
-
optPositiveInt
final static Integer optPositiveInt(JSONObject $self, String name, Integer fallback, Boolean remove)
Returns the value mapped by name if it exists and is a positive integer or can be coerced to a positive integer, or fallback otherwise. If remove is true, then the mapping will be removed from the JSONObject.
-
optPositiveDouble
final static Double optPositiveDouble(JSONObject $self, String name, Double fallback, Boolean remove)
Returns the value mapped by name if it exists and is a positive double or can be coerced to a positive double, or fallback otherwise. If remove is true, then the mapping will be removed from the JSONObject.
-
optNullableString
final static String optNullableString(JSONObject $self, String name, Boolean remove)
Returns the value mapped by name if it exists, or
nullif no such mapping exists, it is not a string or it is empty. If remove is true, then the mapping will be removed from the JSONObject.
-
optNullableBoolean
final static Boolean optNullableBoolean(JSONObject $self, String name, Boolean remove)
Returns the value mapped by name if it exists, coercing it if necessary, or
nullif no such mapping exists. If remove is true, then the mapping will be removed from the JSONObject.
-
optNullableInt
final static Integer optNullableInt(JSONObject $self, String name, Boolean remove)
Returns the value mapped by name if it exists, coercing it if necessary, or
nullif no such mapping exists. If remove is true, then the mapping will be removed from the JSONObject.
-
optNullableLong
final static Long optNullableLong(JSONObject $self, String name, Boolean remove)
Returns the value mapped by name if it exists, coercing it if necessary, or
nullif no such mapping exists. If remove is true, then the mapping will be removed from the JSONObject.
-
optNullableDouble
final static Double optNullableDouble(JSONObject $self, String name, Boolean remove)
Returns the value mapped by name if it exists, coercing it if necessary, or
nullif no such mapping exists. If remove is true, then the mapping will be removed from the JSONObject.
-
optStringsFromArrayOrSingle
final static List<String> optStringsFromArrayOrSingle(JSONObject $self, String name, Boolean remove)
Returns the value mapped by name if it exists and is either a JSONArray of String or a single String value, or an empty list otherwise. If remove is true, then the mapping will be removed from the JSONObject.
E.g. "a", "b" or "a"
-
mapNotNull
final static <T extends Any> List<T> mapNotNull(JSONObject $self, Function1<Pair<String, Object>, T> transform)
Returns a list containing the results of applying the given transform function to each element in the original JSONObject. If the tranform returns
null, it is not included in the output list.
-
-
-
-