Function assertParse

  • You must configure the generic argument T.

    Safe JSON.parse() function with type assertion.

    typia.json.assertParse() is a combination function of JSON.parse() and assert. Therefore, it convers a JSON (JavaScript Object Notation) string to a T typed instance with type assertion.

    In such reason, when parsed JSON string value is not matched with the type T, it throws TypeGuardError or custom error generated by errorFactory. Otherwise, there's no problem on the parsed value, the parsed value would be returned.

    Parameters

    • input: string

      JSON string

    • OptionalerrorFactory: ((props: TypeGuardError.IProps) => Error)

      Custom error factory. Default is TypeGuardError

    Returns never

    Parsed value

    Jeongho Nam - https://github.com/samchon

  • Safe JSON.parse() function with type assertion.

    typia.json.assertParse() is a combination function of JSON.parse() and assert. Therefore, it convers a JSON (JavaScript Object Notation) string to a T typed instance with type assertion.

    In such reason, when parsed JSON string value is not matched with the type T, it throws TypeGuardError or custom error generated by errorFactory. Otherwise, there's no problem on the parsed value, the parsed value would be returned.

    Type Parameters

    • T

      Expected type of parsed value

    Parameters

    • input: string

      JSON string

    • OptionalerrorFactory: ((props: TypeGuardError.IProps) => Error)

      Custom error factory. Default is TypeGuardError

    Returns Primitive<T>

    Parsed value

    Jeongho Nam - https://github.com/samchon