parseJson
function parseJson(value: string): object;
JSON.parse runs first. If it refuses, the text is tokenised again by rules that accept what hand-written configuration usually contains: unquoted keys and single-quoted strings.
Text that neither reader can make sense of throws. This is for configuration a person typed, not for a payload from a service — for that, JSON.parse and its error are clearer.
Parameters
Parameter | Type | Description |
|---|---|---|
|
| The text to parse. It must not be empty. |
Returns
object — the parsed value.
Throws
Exception | Condition |
|---|---|
| the value is not a string, or is empty. |
| neither reader can parse the text. |
Examples
Parsing
parseJson('{"a":1,"b":[1,2]}'); // => {"a":1,"b":[1,2]}
parseJson("{a: 'x', b: 1}"); // => {"a":"x","b":1}
See also
Source
23 September 2026
This documentation was generated with AI (Claude) from the library's source code.