JSON Validator

Check whether text is valid JSON. Errors are reported with line, column, the character that failed and the likely fix. Duplicate keys are flagged.

Processed locally in your browser
Checks syntax against RFC 8259 and flags duplicate keys
JSON
Where it fails
Your input, with the failing line marked, appears here.
Waiting for inputRuns as you type

Diagnostics

    What counts as valid JSON

    JSON is defined by RFC 8259 and ECMA-404. A valid document is a single value: an object, an array, a string, a number, or one of the literals true, false and null. Objects hold zero or more "name": value pairs separated by commas; arrays hold values separated by commas. Strings use double quotes. Whitespace between tokens is ignored.

    That is the whole grammar, which is why most invalid JSON comes from writing JavaScript, Python or YAML habits into a JSON file: trailing commas, single quotes, comments, unquoted keys, True instead of true.

    How this validator reports problems

    The parser stops at the first character it cannot accept and reports three things: the position (line and column), the message (what was found and what was expected), and a hint describing the most likely cause. The right pane shows your document with the failing line highlighted and the exact character underlined, so you do not have to count columns.

    Only the first syntax error is reported. JSON has no error recovery; after the first fault the rest of the document is ambiguous. Fix it, and the validator re-runs as you type.

    When the document is valid, the validator still checks for duplicate keys. RFC 8259 says names within an object should be unique; when they are not, most parsers keep the last value and drop the earlier one without telling you. Duplicates are reported as warnings with their position.

    Messages you may see

    MessageMeaning
    Trailing comma before } / ]A comma follows the last item. Delete it.
    Missing , before propertyTwo properties or values are adjacent. Add a comma after the earlier one.
    Property name must be quotedA key is written without double quotes.
    Strings must use double quotesA string or key uses single quotes.
    Comments are not allowedThe document contains // or /* */. Config formats such as JSONC and JSON5 allow comments; JSON does not.
    Unexpected end of inputA bracket or brace is never closed, or the document was truncated.
    Line break inside a stringA string spans two lines. Usually a missing closing quote.
    Unexpected , after the top-level valueSeveral top-level values. Wrap them in an array, or you may have newline-delimited JSON.
    NaN, Infinity, undefined is not valid JSONJavaScript values with no JSON representation. Use null or a string.
    Unexpected byte order markThe file starts with U+FEFF. Save it as UTF-8 without BOM.

    Validating JSON in code

    JavaScript

    try {
      JSON.parse(text);
    } catch (err) {
      // V8: "Unexpected token } in JSON at position 27"
      // Firefox: "JSON.parse: unexpected character at line 3 column 1 of the JSON data"
      console.error(err.message);
    }

    Python

    import json
    try:
        json.loads(text)
    except json.JSONDecodeError as e:
        print(e.msg, "at line", e.lineno, "column", e.colno)

    Command line

    jq empty data.json            # prints nothing on success, an error with line number otherwise
    python -m json.tool data.json > /dev/null

    Syntax validation versus schema validation

    This tool checks syntax: whether the text is well-formed JSON. It does not check structure: whether "age" is present, is a number and is positive. That is the job of JSON Schema, which needs a schema document to validate against. Syntax validation is a prerequisite; a document that fails here will fail every schema too.

    To fix indentation or minify after validating, use the JSON Formatter. To explore a large valid document, use the JSON Viewer. If the input is actually YAML, the JSON ↔ YAML converter reads it directly.

    navigateEnter openEsc close