Skip to content

@sqlrooms/utils / safeJsonParse

Function: safeJsonParse() ​

safeJsonParse<T>(json): T | undefined

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
jsonstring | null | undefinedThe JSON string to parse.

Returns ​

T | undefined

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