Parses a JSON string and returns the parsed value with optional (unsafe) type assertion.
The expected type of the parsed JSON value
The JSON string to parse
Optional
A function that transforms the result before returning it
The parsed JSON value cast to type T
When the JSON string is malformed
const data = parseJson<{ name: string }>('{"name": "John"}');console.log(data.name); // "John" Copy
const data = parseJson<{ name: string }>('{"name": "John"}');console.log(data.name); // "John"
Parses a JSON string and returns the parsed value with optional (unsafe) type assertion.