core-utils
    Preparing search index...
    • Parses a JSON string and returns the parsed value with optional (unsafe) type assertion.

      Type Parameters

      • T = unknown

        The expected type of the parsed JSON value

      Parameters

      • value: string

        The JSON string to parse

      • Optionalreviver: (this: unknown, key: string, value: unknown) => unknown

        A function that transforms the result before returning it

      Returns T

      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"