optional

inline fun <T> optional(key: String, default: T): T

Returns the value for key decoded as type T, or default if the key is absent.

Parameters

key

The JSON key to look up.

default

The value to return when the key is not present.

Throws

if the key is present but the value cannot be decoded as T.