Validation is simply JSON.parse() in a protective wrapper:
- Your text is handed to the browser's built-in JSON parser — the same strict parser used by
fetch()and Node.js. - If parsing succeeds, the JSON is valid.
- If it throws, the error message is shown, and the reported character position is extracted so you know exactly where to look.
The parser enforces strict JSON: double-quoted strings, no trailing commas, no comments, no single quotes.