UtilDojo

Popular

Menu

Common JSON errors and how to fix each one

Updated 11 October 2026 · 4 min read

jsonerrorsdebuggingvalidation

JSON looks like a JavaScript object, so it is easy to write it the way you write code. The format is much stricter than that, and most parse failures come from a handful of habits carried over from JavaScript, Python or a config file with comments. Each one has a quick fix once you know what the parser is complaining about.

Below are the usual causes, with a before and after for each, followed by a note on how to read an error position and what the formatter on this site does when you turn on its repair mode.

Punctuation mistakes

  • Trailing comma. Before: {"a": 1,} After: {"a": 1}. JSON allows no comma after the last item of an object or array. It is the most common error, usually left behind after deleting the final entry.
  • Single quotes. Before: {'a': 'x'} After: {"a": "x"}. Keys and text values must use double quotes.
  • Unquoted keys. Before: {a: 1} After: {"a": 1}. This is valid in JavaScript and not in JSON.
  • Missing comma. Before: {"a": 1 "b": 2} After: {"a": 1, "b": 2}.
  • Unclosed bracket. Before: {"a": [1, 2 After: {"a": [1, 2]}. A mismatched closer, as in [1, 2}, is also an error.

Values JSON does not have

JSON has strings, numbers, true, false, null, arrays and objects. Nothing else. That rules out comments (// note and /* note */), undefined, NaN, Infinity, Python's None, True and False, and numbers written as +5, .5, 5. or 007.

If a value is missing, use null or leave the key out. If a file needs comments, the usual answers are a separate documentation file, a field such as "_comment" that your code ignores, or a format built for config like YAML.

Dates have no type either. They travel as strings, commonly ISO 8601 such as "2026-10-11T09:30:00Z", and your code parses them.

Strings: escapes and line breaks

A backslash starts an escape, and only \" \\ \/ \b \f \n \r \t and \uXXXX (four hex digits) are valid. A Windows path like "C:\Users" fails because \U is not an escape; write "C:\\Users". Be careful, because "C:\temp" does parse, but quietly turns \t into a tab.

A raw line break or tab inside a string is also invalid. Write \n instead. This usually happens when someone pastes a multi-line value straight into a string.

Problems you cannot see

A byte-order mark (BOM) is an invisible character some editors, especially on Windows, put at the start of a UTF-8 file. Some parsers choke on it with an error pointing at position 0 of a file that looks fine. The formatter here drops it and shows a notice.

Duplicate keys are not strictly an error. The standard says names "should" be unique, and most parsers silently keep the last one. In JavaScript, JSON.parse('{"a":1,"a":2}') gives {a: 2} and the first value vanishes without a warning. The formatter keeps both and flags the repeat with the line where the key first appeared.

Big integers parse fine but can change value in JavaScript, because numbers are 64-bit floats and only safe up to 9007199254740991. Parsing {"id": 12345678901234567890} with JSON.parse gives 12345678901234567000. If an ID is that large, send it as a string. The formatter here shows numbers exactly as written, so it will not expose the problem; your code will.

Reading an error position

Parsers report where they gave up, as a character offset, or a line and column. That point is where the parser noticed a problem, which is often one token after the real mistake. For {"a": 1,} the error points at the closing brace, column 8, because that is where a key was expected after the comma. When a position looks innocent, look at the character just before it.

An "unexpected end of input" error means something was left open earlier in the text. Count brackets backwards from the end rather than staring at the last line.

The formatter here gives the message with line and column and then a plain-language hint, such as "A trailing comma: remove the comma before the }", for the cases above, so you do not have to translate the parser's wording.

Repair mode and its limits

The formatter has an opt-in repair mode for hand-written JSON. It handles trailing commas, converted single-quoted strings, quoted bare keys, stripped comments, turned None, True, False and undefined into their JSON forms, replaced NaN and Infinity with null, escaped raw line breaks in strings, fixed odd numbers and closed brackets left open at the end. It lists each kind of fix with a count, so you can check what changed.

Note that replacing NaN with null changes meaning, so review it. Repair does not guess at everything: a wrong closing bracket such as [1, 2}, or two documents stuck together as {"a":1}{"b":2}, still fail and need a manual fix.

Once the text parses, you can compare it against another version with a JSON diff, or generate TypeScript types from it.

JSON versus a JavaScript object literal

JSON came from JavaScript syntax but is a data format, not code. An object literal can have unquoted keys, single quotes, trailing commas, comments, functions, undefined and NaN. JSON can have none of those. When you need JSON from a JavaScript value, call JSON.stringify, which also drops undefined and functions and turns NaN into null, rather than hand-writing the text.

Frequently asked questions

Why does JSON not allow comments?

The format was kept deliberately minimal so every language could parse it the same way. Comments were removed early on, partly because people used them to carry parsing instructions. Use a documentation file, an ignored field, or a format like YAML for config.

Is JSON with a trailing comma valid?

No. Strict parsers reject it. Some tools accept it as an extension (JSON5, JSONC), but you cannot rely on that when sending data to someone else's API.

Why did my large number change after parsing?

JavaScript stores numbers as 64-bit floats, so integers above 9007199254740991 lose precision. Transmit large IDs as strings, or use a parser that supports BigInt.

What is the difference between a validator and a formatter?

A validator only says whether the text is valid and where it fails. A formatter also re-indents valid JSON so it is readable. Both need the text to parse first.

Try it yourself

All guides