Common JSON Syntax Errors and How to Fix Them

JSON is the default format for APIs, configuration files, and data exchange between services — and it is unforgiving. A JavaScript object with a stray comma might run fine; the same text as JSON gets rejected outright. One missing comma, quote, colon, or bracket makes the entire document invalid, and the parser usually gives you a single terse error message rather than a list of everything wrong.

This guide walks through the JSON syntax errors developers run into most often, shows the invalid and corrected version of each, includes the actual error messages a parser produces, and finishes with a workflow for tracking down errors in a large payload. If you're new to the format itself, start with our guide to what JSON is and how JSON formatting works — this article assumes you know the basics and focuses on what goes wrong.

What Does a JSON Syntax Error Mean?

A JSON syntax error means the text you gave a parser doesn't follow the JSON grammar, so it can't be turned into data. Here's the classic example:

{
  "name": "John"
  "age": 30
}

The problem is a missing comma after "John". Here is the corrected version:

{
  "name": "John",
  "age": 30
}

A parser reads the text from left to right and stops at the first thing that breaks the rules. It doesn't guess what you meant, and it doesn't keep going to collect more errors. In Node.js and Chrome, JSON.parse() on the invalid version above throws:

SyntaxError: Expected ',' or '}' after property value in JSON at position 21 (line 3 column 3)

Notice where it points: line 3, column 3 is the start of "age", not the end of "John" where the comma belongs. The parser only realizes something is wrong when it hits a token it didn't expect, so the reported position is usually just after the actual mistake. Keep that in mind throughout this guide.

One more caveat: the exact wording of error messages differs between engines. The messages quoted here come from Node.js and Chrome (V8); Firefox, Safari, Python, Java, and other parsers phrase them differently — and older engines often just say "Unexpected token" with a character position. The underlying causes are the same everywhere.

1. Missing Commas

Commas separate the properties in an object and the values in an array. Forget one and the parser hits the next key or value unexpectedly.

Invalid:

{
  "name": "John"
  "age": 30
}

Valid:

{
  "name": "John",
  "age": 30
}

This happens most often when you paste a new property into the middle of an existing object, or when you add a new last item and forget that the previous last item now needs a comma after it. The same rule applies to arrays: ["a" "b"] is invalid, ["a", "b"] is valid.

2. Using Single Quotes Instead of Double Quotes

Standard JSON requires double quotes around both property names and string values. Single quotes are not a valid substitute.

Invalid:

{
  'name': 'John'
}

Valid:

{
  "name": "John"
}

Node.js reports this one as Expected property name or '}' in JSON at position 4 — the parser was expecting a double-quoted key and found an apostrophe instead.

Single-quoted "JSON" usually comes from one of two places: a JavaScript object literal (where single quotes are legal), or a Python dictionary printed with print(). Python's print({'name': 'John'}) outputs single quotes, but json.dumps() produces real JSON with double quotes. If you're generating JSON from code, use JSON.stringify() in JavaScript or json.dumps() in Python rather than building the string by hand or printing a data structure.

A related mistake is leaving the property name unquoted entirely — { name: "John" } — which is valid in JavaScript but not in JSON, and produces the same error.

3. Trailing Commas

A trailing comma is a comma after the last property or the last array item. JSON does not allow it.

Invalid:

{
  "name": "John",
  "age": 30,
}

Valid:

{
  "name": "John",
  "age": 30
}

The same rule applies to arrays.

Invalid:

[
  "Apple",
  "Banana",
]

Valid:

[
  "Apple",
  "Banana"
]

Developers hit this constantly because trailing commas are legal in JavaScript object and array literals, and many code formatters even add them by default. Copy an object from source code into a JSON file and the trailing commas come along. It also happens when you delete the last property from a JSON file and forget the comma left behind on the one before it. Node.js reports the object case as Expected double-quoted property name (pointing at the closing brace) and the array case as Unexpected token ']'.

4. Missing or Extra Brackets

Every opening { needs a matching }, and every [ needs a matching ]. Nested structures make it easy to lose track.

Invalid (the inner object is closed, but the outer one never is):

{
  "user": {
    "name": "John"
}

Valid:

{
  "user": {
    "name": "John"
  }
}

When a closing bracket is missing, the parser doesn't complain about the place where the bracket should have been — it reads all the way to the end of the text and only then discovers it's still waiting. Node.js reports this example at the very last character (position 34), and some engines just say Unexpected end of JSON input. So for bracket problems, the error location tells you almost nothing about where the mistake actually is; you need to check the structure. Indenting the JSON consistently makes the mismatch obvious, because the closing braces stop lining up with their openers.

The opposite problem — an extra closing bracket — is reported differently: {"a": 1}} fails with Unexpected non-whitespace character after JSON, because the parser finished one complete value and then found more text. The same message appears if you accidentally paste two JSON objects back to back.

5. Using = Instead of :

In JSON, a key and its value are separated by a colon. Programming languages often use = for assignment, so it's easy to type the wrong one.

Invalid:

{
  "name" = "John"
}

Valid:

{
  "name": "John"
}

Node.js reports Expected ':' after property name in JSON. The underlying point is that JSON is a data format, not code: there are no variables, no assignment, and no expressions. Everything in a JSON document is a literal value.

6. Invalid JSON Values

JSON supports only a small set of value types: strings, numbers, objects, arrays, booleans (true and false), and null. Anything else is invalid.

Invalid:

{
  "active": True
}

Valid:

{
  "active": true
}

true, false, and null must be lowercase and unquoted. True, False, None, NULL, and TRUE are all invalid — Python's capitalized True and None are the usual source when someone pastes a printed dictionary. Also note that "true" with quotes is a valid JSON value, but it's a string, not a boolean, which can cause subtle bugs downstream.

Other values that look reasonable but are not valid JSON:

  • undefined, NaN, and Infinity — JavaScript values with no JSON equivalent. (JSON.stringify() drops properties set to undefined and turns NaN and Infinity into null.)
  • Numbers with leading zeros, like 007, or a leading plus sign, like +5.
  • Hexadecimal numbers like 0xFF.
  • Dates as a special type — JSON has none. Dates are ordinary strings, conventionally in ISO 8601 format like "2026-09-19T10:30:00Z".

7. Unescaped Characters Inside Strings

Some characters have special meaning inside a JSON string and must be escaped with a backslash. The most common offender is a double quote inside a string, because a bare quote looks like the end of the string.

Invalid:

{
  "message": "He said "hello""
}

Valid:

{
  "message": "He said \"hello\""
}

The parser reads "He said " as a complete string, then finds hello where it expected a comma or closing brace. The escape sequences JSON allows are \", \\, \/, \b, \f, \n, \r, \t, and \uXXXX for Unicode characters.

Literal line breaks and tabs inside a string are also illegal. This fails with Bad control character in string literal:

{
  "text": "line one
line two"
}

Write it with an escape sequence instead: "line one\nline two". This trips people up when they paste a multi-line block into a JSON string — including a long Base64 value that's been wrapped across several lines (see our Base64 encoding guide for why that data exists and how it's normally embedded). Remove the line breaks so the value sits on a single line.

8. Duplicate Object Keys

Using the same key twice in one object isn't a syntax error in most parsers, which makes it a sneaky one:

{
  "name": "John",
  "name": "Mike"
}

The JSON specification says names within an object should be unique, but it doesn't define what a parser must do when they aren't. In practice, behavior varies: JavaScript's JSON.parse() quietly keeps the last value ("Mike"), while other parsers may keep the first, report an error, or expose both entries. Because the outcome depends on the implementation, duplicate keys are best treated as a bug even when your parser accepts them — especially in data that will be read by more than one system. This usually comes from merging two objects by hand or copying a block of properties twice.

9. Comments Inside JSON

Comments are one of the most common things developers try to add to JSON, and standard JSON does not support them.

Invalid in standard JSON:

{
  // User information
  "name": "John"
}

Valid:

{
  "name": "John"
}

Neither // line comments nor /* */ block comments are part of the JSON standard, so a strict parser rejects them. The confusion comes from the fact that some related formats do allow comments: JSONC ("JSON with comments") is used by editors like VS Code for its settings files and is accepted by TypeScript in tsconfig.json, and JSON5 is a superset that adds comments, trailing commas, and single quotes. YAML also supports comments. But a file with the extension .json that gets read by a standard parser — including most API clients and files like package.json — must have none. If you need to annotate data, keep the explanation in documentation, or store it as a real field.

10. Incorrect String Escaping

Because the backslash starts every escape sequence, a literal backslash in a value must be written as two. This matters most for Windows file paths.

Invalid:

{
  "path": "C:\Users\John"
}

Valid:

{
  "path": "C:\\Users\\John"
}

Here \U isn't a legal escape, so Node.js reports Bad escaped character in JSON at position 16. The corrected version parses to the string C:\Users\John — the doubled backslashes are just how JSON writes a single one.

The dangerous case is a path where the character after the backslash happens to be a valid escape. "C:\new\table" raises no error at all — but the parser reads \n as a newline and \t as a tab, silently giving you a corrupted value. If a Windows path comes out of JSON looking wrong instead of failing, this is the likely reason. Escape every backslash, or use forward slashes where the consuming software allows them.

A Few More Errors You'll Run Into

  • Unquoted keys: { name: "John" } — valid JavaScript, invalid JSON. Quote every key with double quotes.
  • Empty or missing input: parsing an empty string throws Unexpected end of JSON input. In API work, this usually means the response body was empty or the request failed before any JSON was returned.
  • "[object Object]" is not valid JSON: a JavaScript object was converted to a string implicitly instead of with JSON.stringify(), so the text [object Object] got sent instead of the data.
  • Text before or after the JSON: a stray log line, a byte-order mark, an HTML error page returned instead of JSON, or two objects joined together will all cause an error even though the JSON inside is fine.

How to Find JSON Errors Quickly

When a large payload fails to parse, reading it line by line is the slow way. A more reliable workflow:

  1. Check the error location. Note the position, and the line and column if your parser reports them. If it only gives a character offset, count to it or paste the text somewhere that can show you that spot.
  2. Look immediately before the reported position. As covered above, the parser notices the problem at the first token it can't accept, which is usually right after the real mistake. A missing comma is reported at the next key; a trailing comma is reported at the closing bracket.
  3. Check the usual suspects around that spot: a comma, a quote, a colon, a bracket or brace, or an invalid value like True or undefined.
  4. Fix one error, then validate again. Parsers stop at the first failure, so the next problem stays hidden until the first is fixed. Don't assume one fix means you're done.
  5. Format the JSON once it parses. Consistent indentation makes nesting mistakes — missed brackets, values sitting at the wrong level — easy to see, and it's the quickest way to confirm the structure is what you intended.

Remember that a validator only checks syntax. JSON can be perfectly valid and still be wrong for the API you're sending it to — missing a required field, or using a string where a number is expected. Those are schema problems, not syntax errors, and need to be checked against the API's documentation.

How to Validate JSON

Kravoy's JSON Formatter checks your JSON as you type, using your browser's own JSON parser, and everything happens locally — nothing you paste is uploaded. To use it for troubleshooting:

  1. Paste your JSON into the input panel.
  2. If it's invalid, the parser's error message appears directly under the input, and the output side tells you to fix the error to see a preview. Use the message and the position hints above to find the problem.
  3. Edit the input and the result updates immediately. Once the JSON is valid, the output shows a collapsible tree view (handy for exploring deeply nested data) or a plain-text view.
  4. Once the JSON is valid, use Format to re-indent the input with 2 spaces, 4 spaces, or tabs, or Minify to compress it back onto one line.

The tool shows you what the parser reports; it doesn't fix the JSON for you, which is worth knowing because a silent auto-fix could change what your data means.

Format and inspect JSON with Kravoy's JSON Formatter →

Invalid vs Valid JSON Examples

A quick-reference table for the errors covered above:

ProblemInvalidCorrect
Missing comma"name": "John" "age": 30"name": "John", "age": 30
Single quotes'John'"John"
Unquoted key{ name: "John" }{ "name": "John" }
Trailing comma"age": 30, (last property)"age": 30
Assignment instead of colon"name" = "John""name": "John"
BooleanTruetrue
Invalid valueundefinednull
Unescaped quotes"He said "hello"""He said \"hello\""
Windows path"C:\Users\John""C:\\Users\\John"
Comment// note(remove it)

JSON Syntax Checklist

Before using JSON in an API request, a config file, or a data import, run through this list:

  • Use double quotes for all keys and string values.
  • Separate properties and array items with commas.
  • Use : between every key and value.
  • Match every { with a } and every [ with a ].
  • Avoid trailing commas.
  • Use only valid JSON values: strings, numbers, objects, arrays, true, false, and null.
  • Escape special characters — quotes, backslashes, and line breaks — inside strings.
  • Avoid duplicate keys.
  • Don't use comments in standard JSON.
  • Validate the JSON before sending it to an API.

If you're comparing structured data formats, see our guide to JSON vs XML to understand how their syntax, data types, validation, and common use cases differ.

Frequently Asked Questions

Why is my JSON invalid?

Usually because of a missing comma, a quote problem, a missing colon, an unmatched bracket, or an invalid value such as True or undefined. Check the position in the error message and look just before it.

Can JSON use single quotes?

No. Standard JSON uses double quotes for both string values and object keys. Single quotes are valid in JavaScript and Python, which is why the mistake is so common when moving data between them.

Does JSON allow comments?

Standard JSON does not support comments. Some related formats — JSONC and JSON5 — do, but a normal JSON parser will reject them.

How can I check whether JSON is valid?

Run it through a JSON validator or formatter, or call JSON.parse() in JavaScript or json.loads() in Python and see whether it throws. Kravoy's JSON Formatter does this instantly in your browser and shows the parser's error message if the JSON is invalid.

Why does my JSON work in JavaScript but fail in an API?

A JavaScript object and JSON text are not the same thing. JavaScript object literals allow unquoted keys, single quotes, trailing commas, comments, and values like undefined and NaN; JSON allows none of those. To turn an object into valid JSON text, use JSON.stringify() rather than writing the string by hand.

What does "Unexpected token" mean in a JSON error?

It means the parser hit a character that isn't allowed at that point — for example a single quote where it expected a double quote, or the letter T from True. The token named in the message is where the parser gave up, which is often just after the real mistake. If the "unexpected token" is a <, you've most likely received an HTML page instead of JSON.

Recent Articles