Helpful
    Preparing search index...

    Function tryJsonParse

    Attempts to parse the string buffer as json.

    This is similar to JSON.parse, but instead of throwing an error, it returns the fallback.

    The string buffer that may be json.

    The fallback value in the case that buffer cannot be parsed. Note that parsing the text "null" will return null instead of the fallback. The default value for this is null.

    The parsed value of the buffer when parsed as JSON. If buffer is null, undefined, or does not represent valid JSON, then the fallback is returned.

    • Attempts to parse the string buffer as json.

      This is similar to JSON.parse, but instead of throwing an error, it returns null.

      Type Parameters

      • T = unknown

      Parameters

      • buffer: ZOptional<string>

        The string buffer that may be json.

      Returns ZNullable<T>

      The parsed value of the buffer when parsed as JSON. If buffer is null, undefined, or does not represent valid JSON, then null is returned.

    • Attempts to parse the string buffer as json.

      This is similar to JSON.parse, but instead of throwing an error, it returns a fallback value.

      Type Parameters

      • T

      Parameters

      • buffer: ZOptional<string>

        The string buffer that may be json.

      • fallback: T

        The fallback value in the case that buffer cannot be parsed. Note that parsing the text "null" will return null instead of the fallback.

      Returns T

      The parsed value of the buffer when parsed as JSON. If buffer is null, undefined, or does not represent valid JSON, then fallback is returned.