safeParseLines
Parses newline-delimited JSON (NDJSON, JSON Lines) like parseLines, but returns null
(or fallback) instead of throwing on invalid input.
Accepts / rejects: exactly what parseLines does, with the same ParseLinesOptions.
On invalid input: returns fallback when one is given — even undefined, which is told
apart from an omitted argument — and null otherwise. Never throws. To pass options without
a fallback, pass null as the fallback.
Available since v3.1.3
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
text | string | The newline-delimited JSON text |
Returns
Section titled “Returns”T[] | null — The parsed values typed as T[], or null on invalid input (pass a fallback to get it instead)
Examples
Section titled “Examples”Read NDJSON without throwing
Section titled “Read NDJSON without throwing”Returns null if any line is invalid.
Options without a fallback
Section titled “Options without a fallback”Pass null as the fallback to give options.
Related Types
Section titled “Related Types”ParseLinesOptions
Section titled “ParseLinesOptions”Options for parseLines and safeParseLines.
