Skip to main content
ZEKILO Dev
Format

7 Common JSON Errors and How to Fix Them

Updated 2026.10.03 · 4 min read

Trailing commas, single quotes, unquoted keys, comments, unclosed brackets, NaN and duplicate keys: why each one breaks JSON under RFC 8259 and how to fix it.

Open JSON Formatter & Validator

Most JSON parse failures have the same few causes: syntax that works in JavaScript code but is not part of the JSON standard (RFC 8259). Paste the broken text into the JSON Formatter & Validator and it shows the line and column where parsing stopped, along with the reason. Once you know the seven cases below, you can fix most errors yourself.

The seven errors at a glance

No. Error Broken Fixed
1 Trailing comma {"a":1,} {"a":1}
2 Single quotes {'a':1} {"a":1}
3 Unquoted key {a:1} {"a":1}
4 Comment // x Remove the comment
5 Unclosed bracket {"a":[1,2} {"a":[1,2]}
6 NaN, Infinity or undefined {"a":NaN} {"a":null}
7 Duplicate key {"a":1,"a":2} {"a":2}

Numbers 1 to 6 are syntax errors, so a parser stops reading. Number 7 parses without an error, but different parsers can give different results.

Six syntax errors

1. Trailing comma

In the RFC 8259 grammar, a comma may appear only between two items. JavaScript and Python code both allow a comma after the last item, which is why this error shows up so often in JSON that was edited by hand. For {"a":1,} the tool reports line 1, column 8: “A trailing comma is not allowed in JSON.” Delete the comma right before the closing bracket. The same applies to arrays such as [1,2,].

2. Single quotes

A JSON string begins and ends with a double quotation mark (RFC 8259, section 7). {'a':1} fails at line 1, column 2 with “Strings and keys must use double quotes (“).” This is common when the output of Python’s print for a dictionary is pasted as if it were JSON. Use json.dumps to produce the text and the quotes come out right.

3. Unquoted key

The names in an object are strings too, so they need double quotes. The JavaScript object literal {a:1} is not JSON; it fails at line 1, column 2 with “Wrap the key in double quotes.”

4. Comments

JSON has no comment syntax. Only spaces, tabs and line breaks may appear between values. The input below fails at line 2, column 3 with “JSON does not allow comments.”

{
  // port
  "port": 8080
}

Formats that do allow comments, such as JSONC and JSON5, are separate formats that extend JSON, and a standard JSON parser cannot read them. Keep the explanation in your documentation, or store it as a value under a key that the receiver ignores.

5. Unclosed bracket

Opening and closing brackets must match in kind and in order. In {"a":[1,2} a } arrives before the [ has been closed. The tool reports the error position (line 1, column 10) and also where the bracket was opened: “[ (line 1, column 6) is never closed.” You get the same error when a long document is cut off in the middle, so first check whether the end was lost while copying from a log or a chat message.

6. NaN, Infinity and undefined

A JSON value is one of seven things: an object, an array, a string, a number, true, false or null. Section 6 of RFC 8259 does not permit numeric values that the grammar cannot represent, such as Infinity and NaN. {"a":NaN} fails at line 1, column 6 with “This is not a JSON value. Use null or a number.” The three literal names must be lowercase, so Python’s True is an error as well.

JavaScript’s JSON.stringify turns NaN and Infinity into null, and leaves out properties whose value is undefined. When JSON is built by joining strings by hand, those values end up in the text as they are, so it is better to let a serializer write it.

Not an error, but risky: duplicate keys

Section 4 of RFC 8259 says the names within an object should be unique. When they are not, it calls the behavior of receiving software unpredictable: many implementations report only the last pair, others report an error, and some return every pair. In JavaScript, JSON.parse('{"a":1,"a":2}') gives {"a":2}.

For {"a":1,"a":2} the tool still formats the text as written, and adds a warning at the second key (line 1, column 8): “Duplicate key “a”. Most parsers keep only the last value.” Duplicates usually appear when two configuration files are merged. Keep the one value you mean.

How to read the error position

  • Lines and columns start at 1. Columns count Unicode code points. Hangul, kana and a simple emoji such as 😀 count as one, but an emoji made of several code points (skin tone, family) adds one column per code point.
  • The position is where the parser could not continue. The cause is at that spot or just before it.
  • Only the first error is reported. Fix it and check again.
  • The wording of JSON.parse errors differs between browser engines. This tool uses its own parser, so the position and message are the same in every browser.

Summary

  • JSON is narrower than a JavaScript object literal: double quotes only, no trailing commas, no comments.
  • There are only seven kinds of value. Replace NaN and undefined with null or a number.
  • The top-level value does not have to be an object or an array. "text" and 42 are valid JSON texts.
  • Duplicate keys are not a syntax error, but keep only one.
  • After fixing, check the result again in the JSON Formatter & Validator. Your input is processed only in your browser.

Tools for this guide

Sources

More guides