parseStrict
Parses strict JSON (RFC 8259) — exactly what JSON.parse accepts, nothing more.
Accepts: standard JSON only — double-quoted strings and keys, finite decimal numbers,
true/false/null, objects and arrays, surrounding whitespace.
Rejects: comments, trailing commas, single quotes, unquoted keys, hexadecimal numbers,
NaN/Infinity, a leading byte order mark (U+FEFF), and anything else that isn’t strict JSON.
On invalid input: throws the native SyntaxError from JSON.parse.
Use it to validate input that must be strict JSON, e.g. an API payload. To also read config files with comments or JSON5, use parse. To never throw, use safeParseStrict.
Available since v3.1.3
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
text | string | The JSON text to parse |
Returns
Section titled “Returns”T — The parsed value, typed as T
Examples
Section titled “Examples”Parse strict JSON
Section titled “Parse strict JSON”Exactly what JSON.parse accepts, typed with a generic.
Reject anything that is not strict JSON
Section titled “Reject anything that is not strict JSON”Comments and trailing commas throw a SyntaxError: use it to validate an API payload.
