klyn.io.json.JSON.parse
method
public static parse<TYPE>(notnull json as String) as TYPE
Description

Parses JSON text using the explicitly requested static type.

Natural JSON representations are returned directly when compatible with TYPE. Structured value types such as Rational are materialized only when that exact target type is requested; ordinary maps are never reinterpreted merely because they contain similarly named keys.

Parameters
ParameterDescription
jsonJSON document to parse.
Returns

Parsed value represented as TYPE.

Throws
  • JSONParseException if the document is malformed or a number is outside the supported Long/Double range. Escaped U+0000 is supported in both keys and string values.
  • TypeError if the parsed structure cannot be represented as TYPE.
  • NullException if json is null at runtime; statically null arguments are rejected with TypeError.
Example
ratio = JSON.parse<Rational>("""{"numerator": 1, "denominator": 3}""")
assert ratio == Rational(1, 3)