How-to Guide 5 min read

JSON Trailing Comma and Comments Error: Why It Fails and How to Fix

JSON does not allow trailing commas, comments, single quotes or unquoted keys. See the exact error messages they cause and how to find and fix each one fast.

json trailing commajson comments not allowedexpected double-quoted property name in jsonjson single quotes errorinvalid json fix

The short answer

Standard JSON does not allow a comma after the last item, comments of any kind, single-quoted strings or unquoted keys. JavaScript object literals allow all of these, which is why copied config files and hand-edited JSON break so often. Paste the text into the JSON formatter: if it is invalid, the box shows the parser's error with a position, and you fix the character at that spot. Once it parses, the formatted output appears on the right.

Why JSON is stricter than JavaScript

JSON is a data format defined by a short grammar (RFC 8259 and ECMA-404). That grammar has no rule for comments and no rule for an empty slot after a comma. A JavaScript engine reading code is forgiving; a JSON parser reading data is not. JSON.parse in browsers and Node.js, Python's json module, PHP's json_decode and most API servers follow the strict grammar.

Some tools read a relaxed variant. VS Code's settings.json and tsconfig.json accept comments ("JSON with Comments"), and formats such as JSON5 allow trailing commas. Those files work in the tool that reads them and then fail the moment you paste them into a strict parser.

The errors you will see

The Lazyblink formatter uses your browser's own JSON.parse, so the message wording depends on the browser. These are the messages from the V8 engine used by Chrome, Edge and Node.js 22. Firefox and Safari word them differently but point at the same character.

Input problemExampleV8 error message
Trailing comma in an object{"age": 30,}Expected double-quoted property name in JSON at position …
Trailing comma in an array[1, 2, 3,]Unexpected token ']', "[1, 2, 3,]" is not valid JSON
Line comment// user before a keyExpected property name or '}' in JSON at position …
Block comment/* note */Expected property name or '}' in JSON at position …
Single-quoted key{'name': 'Asha'}Expected property name or '}' in JSON at position 1
Unquoted key{name: "Asha"}Expected property name or '}' in JSON at position 1

Notice that a trailing comma in an object is reported as a problem with the next line. For this input:

{

"name": "Asha",

"age": 30,

}

V8 says "Expected double-quoted property name in JSON at position 33 (line 4 column 1)". Line 4 is the closing brace. The parser saw the comma after 30, expected another key, and found } instead. The comma to delete is on line 3.

How to fix it, step by step

  • Paste the JSON into the input box of the JSON formatter. It parses as you type, so the error appears immediately in a red box.
  • Read the line and column in the message. Go to that spot, then look one token back: the culprit is usually the comma, quote or slash just before it.
  • Make one fix, and watch the message. If it changes to a later position, the first problem is solved and you are on the next one.
  • When the input is valid, the formatted JSON appears in the output panel with 2 or 4-space indentation. Use Copy to take it back to your editor.
  • Fixing each case

    • Trailing commas: delete the comma after the last element of every object and array. Search for ,} and ,], and also for a comma at the end of a line followed by a line that starts with } or ].
    • Comments: delete them. If the note matters, move it into a real field, for example "_comment": "prices exclude GST", and make sure the code reading the file ignores unknown keys.
    • Single quotes: replace them with double quotes around keys and string values. Watch for apostrophes inside text such as 'Ravi's file'; after switching to double quotes the apostrophe is fine as it is.
    • Unquoted keys: wrap each key in double quotes: name becomes "name".
    • Other JavaScript-only values: undefined, NaN, Infinity, functions and dates written as new Date() are not JSON either. Use null, a number, or an ISO date string such as "2026-11-18".

    Stop the problem at the source

    • Generate JSON instead of typing it. JSON.stringify(data) in JavaScript and json.dumps(data) in Python never produce trailing commas or comments.
    • Use the right file type in your editor. If a file must be strict JSON, make sure your editor treats it as JSON rather than "JSON with Comments", so it underlines the extra comma as you type.
    • Validate before you commit or send. A quick paste into the formatter, or python -m json.tool file.json in a terminal, catches the error before an API or build does.
    • Do not strip comments with a quick regex. A pattern that deletes everything after // will also cut through URLs such as "https://example.com" inside strings.

    When the error is not about commas

    If the message says the problem is at position 0, the response is probably not JSON at all, often an HTML error page or an empty body. That case is covered in Unexpected token in JSON at position 0. If the JSON is valid but large numbers change after formatting, see why large numbers change in JSON. To shrink valid JSON for sending, read how to minify JSON.

    Quick reference

    • No comma after the last item: [1, 2, 3], not [1, 2, 3,].
    • No // or /* */ comments.
    • Double quotes only, around every key and every string.
    • Allowed literals: true, false, null, numbers, strings, objects, arrays.
    • The reported position is where the parser gave up. The mistake is usually just before it.

    Frequently asked questions

    Are trailing commas allowed in JSON?

    No. Standard JSON (RFC 8259) does not allow a comma after the last item in an object or array. JSON.parse and most API servers reject it.

    Can I put comments in a JSON file?

    Not in standard JSON. Some tools such as VS Code settings accept 'JSON with Comments', but strict parsers reject them. Remove comments or store the note in a field like "_comment".

    What does 'Expected double-quoted property name in JSON' mean?

    The parser expected a key in double quotes. It usually means there is a trailing comma before a closing brace, or a key wrapped in single quotes or no quotes.

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

    The parser only notices the problem when it reaches the next token. With a trailing comma, it reports the closing brace or bracket, but the comma to delete is on the line before.

    Try this tool on Lazyblink

    Put this guide into practice with our free online tool — no signup required.

    Open tool