klyn.io.json.JSON.parse
method

    public static parse<TYPE>(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

Parameter | Description
--- | ---
`json` | JSON document to parse.

Returns

Parsed value represented as `TYPE`.

Throws

- JSONParseException if the document is malformed.
- TypeError if the parsed structure cannot be represented as `TYPE`.

Example

    ratio = JSON.parse<Rational>("""{"numerator": 1, "denominator": 3}""")
    assert ratio == Rational(1, 3)