mazey
    Preparing search index...

    Function parseJsonSafe

    • Parse a JSON string and return a caller-defined fallback when parsing fails.

      Usage:

      import { parseJsonSafe } from "mazey";

      const data = parseJsonSafe('{"enabled":true}');
      const fallback = parseJsonSafe("invalid", {});

      Type Parameters

      • T
      • F = null

      Parameters

      • value: string

        JSON string to parse.

      • fallback: F = ...

        Value returned when parsing fails. Defaults to null.

      Returns T | F

      The parsed JSON value or the supplied fallback.