parseJson

fun String.parseJson(verbose: Boolean = false): JsonElement

Parses this String as JSON text into a JsonElement.

Extension function on String. The input must be valid JSON: kotlinx.serialization's tree parser accepts any unquoted token (hello, 007, +3, 0x10) as a literal, which would then be re-encoded differently on each platform, so every unquoted value other than true, false, null and a JSON number is rejected. NaN, Infinity and -Infinity, which kotlinx writes for non-finite doubles, are accepted.

Return

the parsed JsonElement

Parameters

verbose

if true, logs the full raw input string at WARN level on parse failure. Avoid this for sensitive payloads, since the input may contain PII or secrets.

Throws

SerializationException

if this string is not valid JSON