Function: parse()
Call Signature
Section titled “Call Signature”parse<
T>(text,fallback):T
Parse JSON text, returning fallback (default undefined) instead of
throwing when text is absent or malformed.
The return type is caller-asserted, exactly like JSON.parse - this only
removes the try/catch, it does not validate. Prefer parseRecord or a
schema when the result is indexed.
Type Parameters
Section titled “Type Parameters”T = unknown
Parameters
Section titled “Parameters”unknown
fallback
Section titled “fallback”T
Returns
Section titled “Returns”T
Example
Section titled “Example”const config = json.parse<Config>(await readFile(path, "utf8"));const tags = json.parse(process.env.TAGS, []);Call Signature
Section titled “Call Signature”parse<
T>(text):T|undefined
Parse JSON text, returning fallback (default undefined) instead of
throwing when text is absent or malformed.
The return type is caller-asserted, exactly like JSON.parse - this only
removes the try/catch, it does not validate. Prefer parseRecord or a
schema when the result is indexed.
Type Parameters
Section titled “Type Parameters”T = unknown
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”T | undefined
Example
Section titled “Example”const config = json.parse<Config>(await readFile(path, "utf8"));const tags = json.parse(process.env.TAGS, []);