parseJson
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, although reformatJson, toFormattedString and toJsonString cannot re-encode them.
The exception's message does not repeat the input, which may hold personal data or secrets and is likely to end up in a log. kotlinx.serialization quotes the input in its parse errors by default; this function turns that off (exceptionsWithDebugInfo = false), so its message gives the offset, what was expected and at most the one character found there, and the exception's input is null. A rejected unquoted token is quoted only as its first 20 characters, with control and line-separator characters escaped.
Return
the parsed JsonElement
Parameters
if true, also logs the full raw input string, line breaks included, at WARN level on parse failure. That is the only way this function puts the input in a log: avoid it for untrusted or sensitive payloads, since the input may contain PII or secrets.
Throws
if this string is not valid JSON