How to Validate JSON: Complete Guide for Developers

JSON syntax errors are one of the most common headaches in web development. A single missing comma or misplaced quote can break your entire API response. Here's everything you need to know about validating JSON correctly.

What is valid JSON?

JSON (JavaScript Object Notation) has strict syntax rules defined by RFC 8259. Unlike JavaScript objects, JSON has zero tolerance for deviation. Here are the rules:

The 7 most common JSON errors

1. Single quotes instead of double quotes

This is the number one mistake. JavaScript accepts single quotes, but JSON does not.

Invalid
{'name': 'DevOpsKit', 'version': 1}
Valid
{"name": "DevOpsKit", "version": 1}

2. Trailing commas

A comma after the last property or array element is invalid JSON, even though JavaScript allows it.

Invalid
{"name": "DevOpsKit", "tools": ["json", "base64",]}
Valid
{"name": "DevOpsKit", "tools": ["json", "base64"]}

3. Unquoted keys

Every key in a JSON object must be a double-quoted string. Unquoted keys work in JavaScript but fail in JSON.

Invalid
{name: "DevOpsKit", version: 1}

4. Comments in JSON

JSON does not support comments of any kind. If you need comments, consider JSONC (JSON with Comments) or YAML instead.

Invalid
{ "port": 8080, // server port "host": "localhost" }

5. Missing commas between properties

Every property except the last needs a comma after it.

6. Unescaped special characters in strings

Characters like newlines, tabs, and backslashes must be escaped: \n, \t, \\.

7. Using undefined or NaN

Only null is valid for empty values. undefined, NaN, and Infinity are not valid JSON.

Validate your JSON instantly

Paste your JSON and get instant validation with syntax highlighting and error detection.

Open JSON Formatter →

How to validate JSON (4 methods)

Method 1: Online validator (fastest)

The quickest way is to paste your JSON into an online JSON validator. You get instant feedback with the exact line and column of any error. No setup required.

Method 2: Command line with jq

If you're on Linux or Mac, jq is the standard tool:

echo '{"name": "test"}' | jq . # Validate a file: jq . config.json # If invalid, jq returns an error with the position

Method 3: Python

import json try: data = json.loads('{"name": "DevOpsKit"}') print("Valid JSON") except json.JSONDecodeError as e: print(f"Invalid JSON: {e}")

Method 4: Node.js

try { const data = JSON.parse('{"name": "DevOpsKit"}'); console.log("Valid JSON"); } catch (e) { console.log("Invalid JSON:", e.message); }

Using an online JSON validator

Our JSON Formatter & Validator does more than just validate — it formats, beautifies, minifies, and syntax-highlights your JSON. It runs 100% in your browser, so your data never leaves your machine.

Key features that save time:

Validating JSON in production code

In production, you should validate JSON at every boundary — API inputs, configuration files, message queues, and webhook payloads. Here are the patterns:

API input validation

Never trust incoming JSON. Always wrap parsing in try/catch and validate the schema, not just the syntax. JSON can be syntactically valid but semantically wrong (missing required fields, wrong data types).

Configuration file validation

Validate config files at startup, not at runtime. If config.json is malformed, fail fast with a clear error message rather than crashing later with a cryptic error.

Schema validation

For strict validation, use JSON Schema — it lets you define expected structure, required fields, data types, and value constraints. Libraries like ajv (JavaScript) and jsonschema (Python) make this straightforward.

Best practices for working with JSON

Try the JSON Formatter now

Free, fast, and 100% client-side. Format, validate, and beautify JSON instantly.

Open JSON Formatter →