MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / parseJsonSafe

Function parseJsonSafe

packages/core/src/utils/Utils.ts:175–187  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

173
174/** Parses a JSON string safely, returning the original value if parsing fails. */
175export function parseJsonSafe<T = unknown>(value: unknown): T {
176 if (typeof value === 'string') {
177 /* v8 ignore next */
178 try {
179 return JSON.parse(value);
180 } catch {
181 // ignore and return the value, as sometimes we get the parsed value,
182 // e.g. when it is a string value in JSON column
183 }
184 }
185
186 return value as T;
187}
188
189/** Collection of general-purpose utility methods used throughout the ORM. */
190export class Utils {

Callers 4

mapJoinedPropFunction · 0.90
parseJsonDefaultMethod · 0.90
mapEntityPropertiesMethod · 0.85
convertJsonToJSValueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected