JSON Validator

Paste JSON and it is checked as you type, with the error line highlighted. Nothing leaves your browser.

0 characters
1

Overview

A JSON validator answers one question: will a strict parser accept this text? Most of the time the answer comes up when something has already broken: a config file that won't load, a webhook that returns 400, or a fixture that a test refuses to read. The error message usually gives you a character offset and not much else, and on a 3,000-line file that is hard to act on.

This validator runs your input through the browser's own JSON.parse, the same strict RFC 8259 parser your JavaScript code uses, while you type. When parsing fails it shows the parser's message and highlights the offending line, so you can fix the problem and watch the status turn green. Valid input gets a summary of its type, key count and node count. Validation happens entirely in your browser and nothing you paste is uploaded. Files over 500 KB are parsed in a background worker so the page stays responsive.

What RFC 8259 actually requires

JSON is defined by RFC 8259 (also published as ECMA-404). The grammar is small, and nearly every validation failure comes from one of these rules:

  • Strings use double quotes only. 'name' is not a string, and object keys must be strings, so {name: 1} is invalid too.
  • No trailing commas after the last array element or object member.
  • No comments of any kind: no //, /* */ or #.
  • Numbers are decimal. No leading zeros (007), no leading +, no hex, no bare .5 or 5., and no NaN or Infinity.
  • Literals are lowercase: true, false, null. True, None and undefined are errors.
  • Control characters must be escaped. A raw tab or newline inside a string is invalid. Write \t and \n instead.
  • Any value can be the top level. "hello", 42 and null are complete JSON documents. The older RFC 4627 required an object or array at the top level, and a few old parsers still enforce that.

Whitespace between tokens is free: spaces, tabs, line feeds and carriage returns can appear anywhere outside a string, so indentation never affects validity.

Common JSON.parse errors and how to fix them

These are the messages current Chrome, Edge and Node.js (V8) print. The position is a zero-based character offset into the string. Newer V8 versions also print a one-based line and column after it, which is why position 7 shows as column 8.

MessageTypical inputFix
Expected double-quoted property name in JSON at position 7 (line 1 column 8) {"a":1,}Remove the trailing comma before }.
Expected property name or '}' in JSON at position 1 {a:1} or {'a':1}Put keys in double quotes.
Expected ',' or '}' after property value in JSON at position 7 {"a":1 "b":2}Add the missing comma between members. This also shows up when a closing brace is missing.
Unexpected token ']', "[1,2,]" is not valid JSON [1,2,]Remove the trailing comma in the array.
Unexpected token 'N', ... is not valid JSON {"a": NaN}Use null or a string. The same message with 'u' means undefined.
Bad control character in string literal in JSON at position 7 a raw tab or newline inside quotesEscape it as \t or \n.
Bad escaped character in JSON at position 8 "\x41", "C:\Users"Use \u0041, or double the backslash: C:\\Users.
Unexpected non-whitespace character after JSON at position 8 {"a":1} {"b":2}Only one top-level value is allowed. Wrap the values in an array, or parse the file line by line as JSON Lines.
Unexpected end of JSON input empty or truncated textCheck for a cut-off response body, or an empty string passed to JSON.parse.

Older Chrome versions phrased the first error as Unexpected token } in JSON at position 42, which still appears in many Stack Overflow answers. Firefox reports the same problem as JSON.parse: expected double-quoted property name at line 3 column 5 of the JSON data. The wording differs between engines, but the fixes are the same. For a string that fails because of its escapes, the JSON escape tool reports the exact bad sequence.

Trailing commas, comments and NaN: almost-JSON

A lot of what people call JSON is really a superset of it. VS Code's settings.json and tsconfig.json are JSONC, which allows comments and trailing commas. JSON5 also allows single quotes, unquoted keys and hex numbers. These files work fine in the tools built for them and fail in a strict parser:

{
  // build output
  "outDir": "dist",
  "strict": true,
}

To turn such a file into real JSON, delete the comments and the comma after true. The Try to fix button handles the common cases: single quotes, unquoted keys, trailing commas and comments. Check its output before you rely on it. Comment removal is text-based, so it also cuts off a URL like "https://..." at the //.

NaN usually comes from a producer and not from hand editing. Python's json.dumps writes NaN and Infinity by default, so a pandas column containing a missing float produces output that browsers reject. Pass allow_nan=False to fail early, or convert the values to None first. JavaScript does the opposite: JSON.stringify(NaN) silently writes null.

Byte order marks and duplicate keys

RFC 8259 says JSON exchanged between systems must be UTF-8, and that implementations must not add a byte order mark (BOM). Some tools still write one. Windows PowerShell 5.1 with Out-File -Encoding utf8 is a common source. JSON.parse then fails on the very first character with Unexpected token '', where the token looks empty because U+FEFF is invisible. Check for it with head -c 3 file.json | xxd. If the output starts with efbb bf, the file has a BOM. Strip it with text.replace(/^\uFEFF/, '') in JavaScript, or open the file with encoding='utf-8-sig' in Python. This page trims surrounding whitespace, including a leading BOM, before parsing. A file can therefore pass here and still fail in a strict parser, so run the xxd check when the error is at position 0.

Duplicate keys are a quieter problem. The RFC only says names should be unique, and it leaves the behavior up to each parser. JSON.parse('{"a":1,"a":2}') returns {a: 2} without any warning, and Python behaves the same way. Because this validator uses JSON.parse, it accepts duplicates as well. To catch them in Python:

def no_dupes(pairs):
    keys = [k for k, _ in pairs]
    dupes = {k for k in keys if keys.count(k) > 1}
    if dupes:
        raise ValueError(f"duplicate keys: {dupes}")
    return dict(pairs)

json.loads(text, object_pairs_hook=no_dupes)

Once the document is valid, use the JSON formatter to indent it consistently. To find what changed between two versions of a config, compare them in the diff checker.

Frequently Asked Questions

Does this validator check against a JSON Schema?

No. It checks syntax, meaning whether the text is well-formed JSON under RFC 8259. Schema validation (required fields, types, enums) is a separate step that needs your schema file and a library such as Ajv.

Why does the error point to the line after the real mistake?

The parser reports where it noticed the problem, not where it started. A missing comma at the end of line 4 is only detected when the next key begins on line 5. Look at the end of the previous line first.

Is a single number or string valid JSON?

Yes. Under RFC 8259 any value can be a complete document, so 42, "text" and null all validate. Only parsers that follow the older RFC 4627 require an object or array.

Are comments ever allowed in JSON?

Not in standard JSON. Formats such as JSONC and JSON5 allow them, but any standard parser, including JSON.parse and Python's json module, rejects them. If you need notes in a config, use a field like "_comment" or switch to YAML.

Is my JSON uploaded anywhere?

No. Parsing runs in your browser with JavaScript, and large inputs use a local Web Worker. Your last input is kept in this browser's local storage so it survives a refresh. Click Clear to remove it.