JSON Tools

JSON Validator: How to Check and Fix JSON Syntax Errors

Validate JSON syntax instantly and get clear, line-specific error messages to quickly find and fix malformed JSON in APIs, configs, and data files.

Published January 15, 2025Updated June 1, 20255 min read

Try the free online tool

Runs entirely in your browser — no signup, no uploads.

Open Tool

A single misplaced comma or an unescaped quotation mark can break a JSON document entirely — and JSON parsers rarely give helpful error messages. A "SyntaxError: Unexpected token" at position 1 is almost useless when you are dealing with a 500-line payload. A dedicated JSON validator tells you exactly which line and character caused the problem.

JSON validation checks that your document conforms to the JSON specification: keys must be strings in double quotes, values must be one of the six JSON types, objects and arrays must be properly closed, and special characters in strings must be escaped. These rules are strict and unforgiving.

This tool validates JSON instantly in your browser, highlights the exact location of every syntax error, and provides a plain-English description of what went wrong — making it the fastest way to debug malformed JSON from any source.

What Is JSON Validation?

JSON validation is the process of checking whether a string conforms to the JSON data format specification (ECMA-404 / RFC 8259). A valid JSON document must have exactly one root value — an object, array, string, number, boolean, or null — and all nested values must follow the same rules recursively.

There are two distinct types of JSON validation: syntax validation (does the text parse correctly?) and schema validation (does the data match an expected structure?). This tool focuses on syntax validation. For schema validation, use the JSON Schema Validator tool instead.

Common syntax errors include: trailing commas, single-quoted strings, unescaped control characters, comments (which JSON does not support), hexadecimal numbers, and undefined or NaN values (both of which are JavaScript concepts not present in JSON).

  • Strings must use double quotes — single quotes are not valid JSON
  • No trailing commas after the last element in an array or object
  • No comments — neither `//` nor `/* */` syntax is allowed
  • Special characters in strings must be escaped: `\"`, `\\`, `\n`, `\t`, `\r`, `\uXXXX`
  • Numbers cannot be NaN, Infinity, or hexadecimal (0xFF) — only standard decimal notation
  • Keys in objects must be strings — bare identifiers like `{name: "Alice"}` are invalid

How to Use This Tool

The validator checks your JSON the moment you paste it, with real-time error highlighting so you can fix issues as you type.

  1. 1

    Paste your JSON

    Paste the JSON you want to validate into the input panel. The tool accepts any JSON — objects, arrays, strings, numbers, or even just `null` or `true`.

  2. 2

    Review the validation result

    A green checkmark means your JSON is valid. A red error badge shows the number of syntax errors detected.

  3. 3

    Read the error details

    Click on an error to jump to the exact line and column where the issue occurs. The error message explains what the parser expected and what it found instead.

  4. 4

    Fix the errors

    Correct each issue in the input panel. Common fixes: replace single quotes with double quotes, remove trailing commas, and escape special characters in strings.

  5. 5

    Confirm the fix

    Once all errors are resolved, the status changes to valid. Copy the corrected JSON or proceed to format or minify it.

Common Use Cases

JSON validation is a first-line debugging step any time JSON enters your system from an untrusted or error-prone source.

  • API integration — validate webhook payloads or third-party API responses before parsing them in your application.
  • Config file authoring — catch syntax errors in `package.json`, `tsconfig.json`, `appsettings.json`, or `.eslintrc.json` before they break your build.
  • Data import pipelines — validate exported JSON files from databases, CMS platforms, or spreadsheet exports before importing them.
  • Manual JSON editing — validate hand-edited JSON files where typos are common and a parser error message would be unhelpful.
  • CI/CD pipelines — run JSON validation as a build step to reject commits that introduce malformed configuration files.

Tips and Best Practices

Validation is the first step, not the last. Here are some practices to build on top of basic syntax checking.

  • Add editor validation — install a JSON language server or linter in your editor (VS Code has built-in JSON validation) so errors appear before you even open a browser.
  • Validate at API boundaries — always validate incoming JSON in your backend before passing it to business logic, even if you trust the source.
  • Use JSON5 for config files — if you find JSON too strict for config authoring (no comments, no trailing commas), consider JSON5 or YAML for config files instead.
  • Automate validation in CI — add a script like `python -m json.tool < config.json > /dev/null` or `jq . config.json > /dev/null` to your CI pipeline.
  • Pair with schema validation — syntax validation tells you the JSON is well-formed; schema validation tells you it has the right structure and types for your use case.

Frequently Asked Questions

What is the difference between valid JSON and valid JavaScript object syntax?

JavaScript object literals allow single-quoted strings, trailing commas, comments, unquoted keys, and special values like `undefined` and `NaN`. JSON allows none of these. A JSON validator checks strictly against the JSON specification, not JavaScript syntax.

Why does my JSON fail validation when it looks correct?

Common invisible issues include: a BOM (byte-order mark) at the start of the file, invisible Unicode whitespace characters inside strings, smart quotes (`“”`) instead of straight double quotes, or a trailing newline that the parser interprets as extra content after the root value.

Can I validate JSON that has comments?

Standard JSON does not support comments. If your file uses comments (common in `.jsonc` or VS Code settings files), strip the comments first or use a JSON5/JSONC parser. This tool validates strict JSON only.

Is a JSON array a valid top-level JSON document?

Yes. A JSON document can have any single valid JSON value as its root: an object `{}`, an array `[]`, a string, a number, a boolean, or null. Arrays are fully valid root values.

How do I validate JSON in a CI pipeline?

Python ships with a built-in validator: `python -m json.tool < file.json > /dev/null`. Node.js can use `node -e "JSON.parse(require('fs').readFileSync('file.json', 'utf8'))"`. Both exit with a non-zero code if the JSON is invalid, which will fail the CI step.

What does `Unexpected token` mean in a JSON error?

It means the parser encountered a character it did not expect at that position. Typically this is a single quote, a letter (from an unquoted key), a comma where none is allowed, or a comment delimiter. The character position in the error message helps you find the exact spot.

Can I validate an empty string as JSON?

An empty string `""` is a valid JSON value (a JSON string). However, a completely empty document (zero bytes, or only whitespace) is not valid JSON, because there is no root value present.

jsonjson validatorvalidate jsonjson syntaxjson error

Ready to use this tool?

Free, instant, no account required. Runs entirely in your browser.

Open Tool

More JSON Tools Guides