Skip to content

@sqlrooms/utils / safeJsonParse

Function: safeJsonParse()

safeJsonParse<T>(json): undefined | T

Parse a JSON string and return the parsed object. If the string is not valid JSON, return undefined.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
jsonundefined | null | stringThe JSON string to parse.

Returns

undefined | T

The parsed object or undefined if the string is not valid JSON.