Skip to content
ToolkitHub

JSON Validator

Validate JSON syntax

Guide

Common reasons JSON fails to parse

By Logappradeep · ServiceNow developer

A JSON validator answers one question: would a standards-compliant parser accept this text? JSON's grammar, defined in RFC 8259 and ECMA-404, is deliberately small and strict. That strictness is what makes JSON portable across languages, but it also means a single stray character makes the whole document unreadable to the program that receives it.

The mistakes that break JSON most often

  • Trailing commas: {"a": 1,} or [1, 2,]. JavaScript tolerates them; JSON does not.
  • Single quotes: {'name': 'Ada'}. Strings and keys must use double quotes.
  • Unquoted keys: {name: "Ada"} is a JavaScript object literal, not JSON.
  • Comments: // and /* */ are not part of the grammar.
  • Invalid numbers: leading zeros (007), a leading plus sign, NaN, Infinity, and hexadecimal literals are all rejected.
  • Non-JSON values: undefined, functions, and dates written as new Date() have no JSON form.
  • Raw control characters in strings: a literal tab or line break inside quotes must be written as \t or \n.
  • Unbalanced brackets after copying only part of a larger document.

Reading the error message

When validation fails, a status bar shows the parser's message, for example "Unexpected token" or "Expected property name", together with the line and column where parsing stopped. The reported spot is where the parser gave up, which can be just after the real mistake. A missing comma, for instance, is typically reported at the start of the next value. The exact wording differs between browsers because each JavaScript engine writes its own messages.

Syntax validation versus schema validation

This tool checks syntax: whether the text is well-formed JSON. It does not check meaning, such as whether age is a number, whether email is present, or whether an array has at least one item. That is the job of JSON Schema, a separate vocabulary for describing the expected shape of a document, which is enforced by schema validator libraries in your application or test suite. A document can be perfectly valid JSON and still be the wrong data.

Related formats

Many tools accept relaxed dialects. JSONC (used by VS Code and tsconfig files) allows comments, and JSON5 adds unquoted keys, single quotes, and trailing commas. Those files will be flagged as invalid here, which is correct if the consumer expects strict JSON. Also watch for an invisible byte order mark at the start of files saved by some Windows editors; strict parsers may reject it.

Validation happens in your browser, so you can safely check payloads that contain internal data.

Frequently asked questions

Why is my JavaScript object rejected?

JavaScript object literals allow unquoted keys, single quotes, trailing commas, and comments. JSON allows none of these, so convert the object with JSON.stringify or fix those details by hand.

Does this validate against a JSON Schema?

No. It checks syntax only. Use a JSON Schema validator in your code or tests to check required fields and data types.

Is an empty string valid JSON?

No. A JSON text must contain exactly one value, though that value can be as small as null, true, a number, or an empty string written as "".

Can the top level be an array or a plain value?

Yes. RFC 8259 allows any JSON value at the top level, including arrays, strings, numbers, true, false, and null.

Why does the error point to the wrong line?

Parsers report where they detected the problem, which is often just after the actual mistake. Check the previous line for a missing comma or quote.