Quick answer

The parser encountered a character or token it did not expect at the current position.

YAML Unexpected Character

The parser encountered a character or token it did not expect at the current position. This often means a typo, wrong character, or encoding issue.

Common causes

How to fix

Examples

Bad

name:
	value: 1

Good

name:
  value: 1

YAML Unexpected Character errors happen when a parser encounters a symbol, token, or byte sequence that does not fit YAML syntax at the current position. This usually points to a typo, a misplaced colon, an invalid indentation level, a hidden control character, or an encoding issue such as a non-UTF-8 file. Developers, DevOps teams, and content pipelines use YAML validation to catch these problems before deployment, configuration loading, or CI/CD execution. This checker helps you identify where the structure breaks so you can correct the document and restore valid parsing.

How This Validator Works

This validator checks YAML content for characters and tokens that do not match the expected syntax rules. YAML is sensitive to indentation, quoting, line breaks, and special characters, so even a small formatting issue can cause a parse failure. The tool helps surface the likely problem area by looking for invalid symbols, malformed scalars, inconsistent spacing, and encoding-related anomalies.

Common Validation Errors

Unexpected character errors often appear when YAML syntax is technically close to correct but still invalid for the parser. These issues can be subtle because the document may look readable to humans while still violating YAML grammar.

Where This Validator Is Commonly Used

YAML validation is commonly used anywhere structured configuration or machine-readable content needs to be parsed reliably. Because YAML is widely used in automation and infrastructure, syntax errors can affect deployment, service startup, and application configuration.

Why Validation Matters

Validation helps catch syntax problems before they interrupt automated systems or cause configuration drift. YAML is compact and readable, but that also means small formatting mistakes can have outsized effects. A single unexpected character can prevent a parser from loading a file, which may stop a deployment, break a service configuration, or cause a data pipeline to fail. Early validation improves reliability, reduces debugging time, and makes configuration changes safer to review.

Technical Details

YAML parsers process content as a sequence of tokens, using indentation and punctuation to determine structure. An unexpected character error usually means the parser encountered a token that does not belong in the current grammar context. The issue may be local to one line, but the visible error can sometimes be caused by a previous line that left the parser in an unexpected state.

Issue Type What It Usually Means
Unexpected character A symbol or byte appeared where the parser expected valid YAML syntax
Unexpected token The parser recognized a token, but it does not fit the current grammar position
Encoding-related failure The file may contain invalid bytes, smart punctuation, or a non-UTF-8 encoding
Structure mismatch Indentation, quoting, or block formatting caused the parser state to break

FAQ

What does “YAML unexpected character” mean?

It means the parser found a symbol, byte, or token that does not fit the YAML syntax expected at that point in the file. This often happens because of indentation mistakes, unquoted special characters, or hidden formatting copied from another source. The error is usually syntax-related rather than data-related.

Is this usually caused by indentation?

Very often, yes. YAML relies heavily on indentation to define structure, so a single misplaced space or tab can change how the parser reads the document. Even if the line looks visually correct, the parser may interpret it differently. Checking nearby lines is usually the best first step.

Can special characters break YAML?

Yes. Characters such as colons, hashes, braces, brackets, and quotes can change meaning depending on context. If they appear in a plain string without quotes, the parser may treat them as syntax instead of text. Quoting the value often resolves the issue when the content is meant to be literal.

Do hidden characters cause YAML parse errors?

They can. Copying text from documents, chat tools, or web pages may introduce smart quotes, non-breaking spaces, zero-width characters, or other invisible bytes. These characters are hard to spot manually but can still break parsing. A validator is useful for detecting these less obvious problems.

Why does the error point to one line when the real problem is elsewhere?

Parsers often report the location where they first noticed the syntax mismatch, not necessarily where the original mistake began. A missing quote, bad indent, or broken block earlier in the file can cause a later line to fail. Reviewing the surrounding structure is usually more effective than checking only the reported line.

Does YAML need UTF-8 encoding?

Most modern YAML tools expect UTF-8, and using another encoding can lead to unexpected character or token errors. If a file was saved from an older editor or copied from another system, encoding mismatches may be part of the problem. Re-saving the file as UTF-8 is a common troubleshooting step.

Are tabs allowed in YAML?

Tabs are generally discouraged and often rejected in indentation. YAML parsers typically expect spaces for structural indentation, because tabs can be interpreted inconsistently across tools. If you see a parse error near the start of a line, replacing tabs with spaces is a practical fix to test first.

How is this different from a generic syntax error?

A generic syntax error is a broad category, while an unexpected character error is more specific. It tells you the parser encountered a token it could not accept in the current context. That specificity helps narrow the search to punctuation, encoding, quoting, or indentation issues instead of unrelated logic problems.

Related Validators & Checkers

FAQ

What encoding should YAML use?
YAML files should be UTF-8. Some parsers support UTF-16; avoid other encodings without a BOM or declaration.
Why does YAML say unexpected tab?
Many parsers disallow tabs for indentation; use spaces instead.

Fix it now

Try in validator (prefill this example)

Related

All tools · Canonical