android-components / mozilla.components.support.ktx.android.org.json / org.json.JSONObject

Extensions for org.json.JSONObject

putIfNotNull

fun JSONObject.putIfNotNull(key: String, value: Any?): Unit

Puts the specified value under the key if it's not null

sortKeys

fun JSONObject.sortKeys(): JSONObject

Sorts the keys of a JSONObject (and all of its child JSONObjects) alphabetically

tryGetInt

fun JSONObject.tryGetInt(key: String): Int?

Returns the value mapped by {@code key} if it exists, and if the value returned is not null. If it's null, it returns null

tryGetLong

fun JSONObject.tryGetLong(key: String): Long?

Returns the value mapped by {@code key} if it exists, and if the value returned is not null. If it's null, it returns null

tryGetString

fun JSONObject.tryGetString(key: String): String?

Returns the value mapped by {@code key} if it exists, and if the value returned is not null. If it's null, it returns null