JSON Formatter

JSON Validator

Invalid JSON is one of the most common causes of API and config errors. Here is how to validate JSON instantly, fix common errors, and understand what makes JSON invalid.

Validate JSON online in one click

Go to quicktoolshub.org/json-formatter. Paste your JSON and click Validate. Valid JSON shows a green confirmation. Invalid JSON shows the exact error message from the parser — telling you what the problem is and where it is.

The most common JSON errors

ErrorExample (invalid)Fix
Trailing comma{"a": 1,}Remove the comma after the last item
Single quotes{'key': 'value'}Use double quotes: {"key": "value"}
Unquoted key{key: "value"}Quote the key: {"key": "value"}
Comment{"a": 1 // note}Remove comments — not allowed in JSON
Undefined value{"a": undefined}Use null: {"a": null}
Missing comma{"a": 1 "b": 2}{"a": 1, "b": 2}

Validate JSON in JavaScript

function isValidJSON(str) {
  try {
    JSON.parse(str);
    return true;
  } catch {
    return false;
  }
}

// With error details
function validateJSON(str) {
  try {
    const data = JSON.parse(str);
    return { valid: true, data };
  } catch (e) {
    return { valid: false, error: e.message };
  }
}

Validate JSON in Python

import json

def validate_json(json_string):
    try:
        data = json.loads(json_string)
        return True, data
    except json.JSONDecodeError as e:
        return False, str(e)

valid, result = validate_json('{"key": "value"}')
# True, {"key": "value"}

valid, error = validate_json("{'key': 'value'}")
# False, "Expecting property name enclosed in double quotes: line 1 column 2 (char 1)"

JSON vs JavaScript object literals

A common source of confusion: valid JavaScript objects are NOT always valid JSON. JSON requires double quotes, disallows trailing commas, and has no support for comments, undefined, Infinity or NaN. If you are copying an object literal from JavaScript code into JSON, you will likely need to fix it first.

Where invalid JSON commonly comes from

Invalid JSON appears in several common workflows. Copying a JavaScript config file (like a webpack or package.json that uses comments or unquoted keys). Manually editing a JSON file in a text editor and accidentally adding a trailing comma. Receiving API response data that has been partially corrupted or truncated. Generating JSON from a template string in code without proper escaping. Copying JSON from a PDF or document where smart quotes have replaced straight quotes. Each of these is a different fix — the validator's error message tells you exactly which one you're dealing with.

Validate your JSON now — free, instant

Paste your JSON and click Validate. See the exact error if it fails. No sign-up, no server.

Open JSON Validator →

Frequently asked questions

How do I validate JSON online?

Go to quicktoolshub.org/json-formatter, paste your JSON and click the Validate button. If the JSON is valid, you see a green 'Valid JSON' confirmation. If it is invalid, the exact error message shows what is wrong. You can also click Format JSON — it will validate and format in one step, or show the error if the JSON is invalid.

What makes JSON invalid?

Common JSON errors: trailing commas after the last item in an object or array (not allowed in JSON, but allowed in JavaScript); single quotes instead of double quotes around strings; unquoted property keys; comments (// or /* */ — not allowed in JSON); undefined, NaN or Infinity values (not valid JSON values); missing commas between items; and mismatched brackets or braces.

How do I validate JSON in JavaScript?

Use a try/catch around JSON.parse: function isValidJSON(str) { try { JSON.parse(str); return true; } catch { return false; } }. For more detail: try { const data = JSON.parse(str); return { valid: true, data }; } catch (e) { return { valid: false, error: e.message }; }

How do I validate JSON in Python?

Use json.loads in a try/except: import json; try: data = json.loads(json_string); print('Valid'); except json.JSONDecodeError as e: print(f'Invalid: {e}'). The JSONDecodeError includes the line number and column position where the error occurred.

What is the difference between JSON and JavaScript object literals?

JSON is a strict subset of JavaScript object notation. Key differences: JSON requires double quotes around all strings and property keys (JavaScript allows single quotes and unquoted keys); JSON does not allow trailing commas (JavaScript does in modern syntax); JSON does not support comments, undefined, Infinity or NaN values; JSON requires specific number formatting. Valid JSON is always valid JavaScript, but not all JavaScript objects are valid JSON.

How do I fix 'Unexpected token' in JSON?

An 'Unexpected token' error means the parser found a character it did not expect. Common fixes: replace single quotes with double quotes; remove trailing commas; remove JavaScript comments; ensure all string values are quoted; check for unescaped special characters in strings (use \" for a quote inside a string); verify that all brackets and braces are matched and properly nested.