โ† Back to Blog

How to Validate JSON Online

2026-04-04 ยท 5 min read

What Makes JSON Valid?

Valid JSON must satisfy all of the following conditions: the entire document is a valid JSON value (one of: object, array, string, number, boolean, or null); all strings (including object key names) are enclosed in double quotes; no trailing commas (e.g., after the last element in an array or object); no comments; brackets/braces fully paired; special characters properly escaped.

Note that "valid JSON" and "valid business data" are different things โ€” JSON can be syntactically perfect but have field values that don't meet business rules (e.g., negative age). That requires JSON Schema validation to check.

Most Common JSON Syntax Errors

1. Trailing comma โ€” The most common error, often introduced when copying JSON from code:

// ้”™่ฏฏ / Wrong:
{"name": "Alice", "age": 30,}

// ๆญฃ็กฎ / Correct:
{"name": "Alice", "age": 30}

2. Unquoted key names:

// ้”™่ฏฏ / Wrong:
{name: "Alice"}

// ๆญฃ็กฎ / Correct:
{"name": "Alice"}

3. Single quotes used:

// ้”™่ฏฏ / Wrong:
{'name': 'Alice'}

// ๆญฃ็กฎ / Correct:
{"name": "Alice"}

Escaping Special Characters in Strings

In JSON strings, these characters must be escaped with a backslash: double quote \"; backslash \\; forward slash \/ (optional); newline \n; carriage return \r; tab \t; Unicode characters \uXXXX.

Unescaped special characters in a JSON string cause parse failures. For example, storing multi-line text as a JSON string requires newlines to be escaped as \n โ€” you cannot include actual line breaks inside the string.

How to Use an Online Validation Tool

  1. Open an online JSON validation tool and paste the JSON to validate into the input area.
  2. Tools typically validate in real-time as you type, highlighting problematic sections in the editor.
  3. If JSON is invalid, read the error message: it usually shows something like "Unexpected token at line X, column Y", pinpointing the exact error location.
  4. Fix the indicated location based on the error message, then re-validate until it passes.
  5. Once validation passes, the tool typically displays "Valid JSON" and offers the option to format for display.

JSON Validation in Programming Languages

The simplest way to validate JSON in code is to try parsing it:

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

# Python
import json
def is_valid_json(s):
    try:
        json.loads(s)
        return True
    except json.JSONDecodeError:
        return False

For JSON Schema validation, each language has mature libraries: JavaScript has ajv; Python has jsonschema; Java has networknt/json-schema-validator; Go has santhosh-tekuri/jsonschema.

JSON Validation Automation in CI/CD

Automatically validating JSON files in a CI/CD pipeline is an effective way to prevent configuration errors from reaching production. Common CI/CD JSON validation methods:

JSONC and JSON5: JSON Formats with Comments

Standard JSON doesn't support comments, which is inconvenient for configuration files. Two extended formats have emerged: JSONC (JSON with Comments) is used by VS Code and similar tools. It extends standard JSON to allow // and /* */ comments; files typically have the .jsonc extension. JSON5 is a more permissive superset, additionally supporting comments, single-quoted strings, trailing commas, and more, designed to make JSON more human-friendly.

Note: JSONC and JSON5 are non-standard extensions that cannot be parsed by standard JSON parsers โ€” they require specialized parsing libraries. They should not be used for API data exchange; only for configuration file contexts.

Try the free tool now

Use Free Tool โ†’