safeJsonParse
Parses a JSON string, returning null (or a fallback) on any parse failure.
Unlike JSON.parse, this never throws. Invalid JSON strings and other
parsing edge-cases resolve to null or the provided fallback.
Available since v2.0.0
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
input | string | The JSON string to parse. |
Returns
Section titled “Returns”T | null — The parsed value typed as T, or fallback on failure.
Examples
Section titled “Examples”Parse valid JSON
Section titled “Parse valid JSON”Returns the parsed value when the input is valid JSON.
Return null on invalid input
Section titled “Return null on invalid input”Returns null instead of throwing when JSON is malformed.
Use a fallback value
Section titled “Use a fallback value”Returns the provided fallback when parsing fails.
