JSON, XML & YAML Error Messages

Comprehensive guide to common parsing errors and how to fix them. Find your error message below for instant solutions.

๐Ÿ’ก Quick Fix Tips

JSON: Use double quotes, no trailing commas, no comments
XML: Close all tags, match case, escape special chars
YAML: Use spaces not tabs, consistent indentation

{ } JSON Errors

SyntaxError: Unexpected token

The parser found a character that doesn't belong in valid JSON at the specified position.

Common Causes:

  • Trailing comma after the last element
  • Single quotes instead of double quotes
  • Unquoted property names
  • Comments in JSON (not allowed)
  • Missing comma between elements

โŒ Wrong

{
  "name": "John",
  "age": 30, // trailing comma!
}

โœ“ Correct

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

SyntaxError: Unexpected end of JSON input

The JSON string ended before all structures were properly closed.

Common Causes:

  • Missing closing brace }
  • Missing closing bracket ]
  • Incomplete string (missing closing quote)
  • Empty input string

โŒ Wrong

{
  "users": [
    {"name": "John"}
  // missing ] and }

โœ“ Correct

{
  "users": [
    {"name": "John"}
  ]
}

SyntaxError: Expected property name or }

An object was expected to have a property name but found something else.

Common Causes:

  • Extra comma creating empty slot
  • Missing property name before colon
  • Typo in property structure

โŒ Wrong

{
  "name": "John",
  , // extra comma
  "age": 30
}

โœ“ Correct

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

SyntaxError: Unexpected string

A string appeared where it wasn't expected, usually due to missing comma.

Common Causes:

  • Missing comma between properties
  • Missing colon after key

โŒ Wrong

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

โœ“ Correct

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

SyntaxError: Bad escaped character

An invalid escape sequence was found in a string.

Common Causes:

  • Invalid escape like \x instead of \u
  • Unescaped backslash
  • Invalid unicode escape sequence

โŒ Wrong

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

โœ“ Correct

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

</> XML Errors

XML Parsing Error: not well-formed

The XML document doesn't follow proper XML syntax rules.

  • Missing closing tag
  • Mismatched tag names
  • Invalid characters in element names
  • Missing root element

XML Parsing Error: mismatched tag

An opening tag doesn't match its closing tag.

  • Typo in tag name
  • Wrong closing tag order
  • Case sensitivity (XML is case-sensitive)

XML Parsing Error: undefined entity

An entity reference (like &foo;) is not defined.

  • Using HTML entities without declaration
  • Unescaped & character
  • Missing entity definition in DTD

--- YAML Errors

YAML Exception: bad indentation

Indentation levels are inconsistent or use tabs instead of spaces.

  • Mixing tabs and spaces
  • Inconsistent indentation levels
  • Wrong number of spaces

YAML Exception: mapping values not allowed

A colon appeared in an unexpected location.

  • Unquoted string containing colon
  • Missing space after colon
  • Invalid key format

YAML Exception: duplicate key

The same key appears more than once in a mapping.

  • Copy-paste error
  • Accidental duplicate key names

How to Triage an Error Fast

1. Read the position

If the error includes a line or column, start there. The real mistake is often just before that point.

2. Check the format clue

Words like token, brace, tag, or indentation usually point to JSON, XML, or YAML-specific issues.

3. Remove the last change

If the file was working before, undo the most recent edit and re-validate. That is usually the fastest way to isolate the break.

4. Validate with the right tool

Use JSON, XML, or YAML validation before manual debugging so syntax errors are separated from application logic.

Common Clues by Format

JSON clues

  • Unexpected token or unexpected string
  • Trailing comma or missing comma
  • Double quotes required around keys and strings

XML clues

  • Not well-formed or mismatched tag
  • Unescaped ampersand or invalid entity
  • Opening and closing tags must match exactly

YAML clues

  • Bad indentation or mapping value errors
  • Tabs instead of spaces
  • Ambiguous colons, booleans, or duplicate keys

Validate Your Code

Use our free validators to find and fix errors instantly