Skip to main content

Function: safeJsonParseArray()

safeJsonParseArray<T>(json: string, elementValidator: (item: unknown) => item is T): SafeJsonResult<T[]>

Defined in: shared/utils/jsonSafety.ts:140

Parse JSON array with element validation.

Type Parametersโ€‹

Tโ€‹

T

Parametersโ€‹

jsonโ€‹

string

JSON string to parse

elementValidatorโ€‹

(item: unknown) => item is T

Type guard for array elements

Returnsโ€‹

SafeJsonResult<T[]>

Safe result object with validated array or error

Exampleโ€‹

const result = safeJsonParseArray(
jsonString,
(item): item is User => typeof item === "object" && item !== null
);

Throwsโ€‹

Never throws - all errors are captured and returned in the result object