Function parseJSON

  • Safely parses a JSON string or returns undefined if is invalid.

    Remarks

    JSON.parse is unsafe by default, allowing proto poisoning. This function takes care of it while making its types safer as well.

    Example

    parseJSON('{"__proto__":"😈"}'); // {}
    parseJSON("invalid"); // undefined

    See

    attempt

    Type Parameters

    • Output extends JSONValue = JSONValue

      Generic of the output (has to be a JSONValue).

    Parameters

    • Rest ...parameters: [string: string]

    Returns Maybe<Output>

    Parsed string or undefined if invalid JSON.