ByteTips.

Guide

How to Validate JSON Online

Validating JSON means checking it against the strict JSON grammar — no trailing commas, no comments, double quotes only. Here are the 7 errors that break everything and how to read the error message.

October 19, 2026 · 5 min read · Shayan · JSON & Data

🛠️ Try it in your browser — no uploads

Skip the manual work and run this on your own input with the free JSON Formatter & Validator.

Open free JSON Formatter & Validator on Byte-Kit →

Short answer: paste the text into a JSON validator — or run JSON.parse() on it. Valid JSON is stricter than the JavaScript object literals you write every day: keys and strings need double quotes, trailing commas are forbidden, comments are not allowed, and the whole document must be a single value. Nearly every validation failure is one of seven mistakes, and modern parsers point at the exact position.

What valid JSON actually allows

The grammar is tiny: objects with double-quoted keys, arrays, strings in double quotes, numbers, true, false, and null. That is the whole language. Everything developers habitually write in config files and then wonder why the parser rejects — single-quoted strings, trailing commas, comments, unquoted keys, NaN, Infinity, undefined — is not JSON. If your data comes from a human-edited file, assume one of those is present.

The 7 errors that break everything

  • Trailing commas: {"a": 1,} — legal in JavaScript, fatal in JSON. The most common error in hand-written config.
  • Single quotes: {'a': 1} — JSON strings take double quotes only. A quick find-and-replace fixes it only if no string contains an apostrophe; safer to re-quote properly.
  • Unquoted keys: {a: 1} — every key must be a double-quoted string.
  • Comments: // and /* */ are not part of JSON. (JSONC — JSON with Comments — is a VS Code / TypeScript-config dialect, not JSON; parsers will reject it.)
  • Multiple top-level values: {"a":1} {"b":2} — one document, one value. Newline-separated records are JSON Lines, a different format.
  • Control characters in strings: raw newlines or tabs inside a "string" must be escaped as \n and \t.
  • NaN, Infinity, undefined: not JSON values. Use null, or encode them as strings if you must round-trip them.

Reading the error message

JSON.parse('{"a": 1,}');
// SyntaxError: Unexpected token '}', "{"a": 1,}" is not valid JSON

JSON.parse('{"a": 1');
// SyntaxError: Unterminated string in JSON at position 8

Modern JavaScript engines quote the offending input and give you a position — count characters from the start (position 0) to land on the exact spot. The reported position is where the parser gave up, which is usually one token after the real mistake: a missing closing quote at position 8 gets reported a few characters later. When the position points at the very end of the input, suspect a missing closing brace or bracket.

function validateJson(text) {
  try {
    JSON.parse(text);
    return { valid: true };
  } catch (e) {
    return { valid: false, error: e.message };
  }
}

validateJson('{"a": 1,}');
// { valid: false, error: 'Unexpected token ...' }

Valid syntax is not enough: validate the shape

Parsing tells you the JSON is well-formed; it says nothing about whether it has the fields your code needs. For that, validate against a schema: JSON Schema (with a validator like Ajv in JavaScript) lets you declare required fields, types, and formats, and get structured errors — "age must be a number" instead of a crash three functions later. Syntax validation catches typos; schema validation catches wrong data.

Quick answers

  • Can I validate a huge file? Yes, but do not paste multi-megabyte files into a browser tab casually — parsing blocks the page while it runs. For large files, validate from the command line: python -m json.tool file.json or jq empty file.json both parse and report errors without loading a UI.
  • Is there a way to allow comments? Use JSONC only where the consumer supports it (VS Code settings, tsconfig). If the consumer is JSON.parse, strip comments first — or better, keep the source as JSONC and generate strict JSON from it.
  • Why does my API return HTML instead of JSON? That is the classic fetch bug: the server returned an error page (or you hit the wrong URL) and your code tried to parse HTML as JSON. Covered in detail in the linked post below.

Try it

Paste the document into the JSON Formatter & Validator — it validates as you type, highlights the exact error position, and pretty-prints the fixed result, all in your browser. If the error mentions HTML where JSON should be, Fix "Unexpected token < is not valid JSON" walks through that specific bug.

Written by Shayan — Creator of Byte-Kit & ByteTips. Building private developer tools.

More JSON & Data guides