Code Beautifier
end of the stream or a document separator is expected

Fix "end of the stream or a document separator is expected"

YAML found content it cannot attach to the document: a second top-level value, text after a closed block, or a key after a scalar. Causes and fixes.

Input that triggers it

version 2
services:
  web: nginx
Open YAML Validator on its own page
Draft saved locally.

Local workspace

Named projects in IndexedDB · Local only — never synced to our servers. Worksp

Open manager

Batch workspace

Format multiple files locally in one run.

yaml
json

What the error means

A YAML document holds exactly one top-level node: a mapping, a sequence, or a single scalar. Once the parser has finished that node, the only things it will accept are the end of the input or a document separator, ---, which starts a new document. end of the stream or a document separator is expected means it finished the top-level node and then found something else.

The example illustrates the most surprising version of this. Line one, version 2, has no colon, so YAML reads it as a plain scalar — the string "version 2" — and that scalar is the entire document. Line two then tries to start a mapping, which cannot follow a completed scalar, and the parser stops there. The real mistake is the missing colon on line one; the error is reported on line two.

Why it happens

  • A missing colon on the first line, which turns what should be a key into a whole-document scalar, as above.
  • Two top-level values with no separator, typically two config files pasted together.
  • Content after a block that was closed by dedenting to column zero, for example a stray line of text at the end of a file.
  • A stray --- or ... in the wrong place, which ends the document early so that everything after it is unattached.
  • A copied snippet that starts with a list item (- name: x) followed by a mapping key at column zero.

How to fix it

  1. Paste the document into the validator above and note the line in the error card.
  2. Look at the line before it first. If that line has a key without a colon, add the colon. This resolves the example.
  3. If there are genuinely two documents, put --- on its own line between them. The validator reports the document count, so you can confirm it now sees two.
  4. If a trailing line does not belong anywhere, delete it or indent it under the key it was meant for.

The corrected example:

version: 2
services:
  web: nginx

If it still fails

  • Docker Compose and CI files are the usual sources. Paste the fixed file into YAML to JSON; if the JSON shows a top-level string where you expected an object, a colon is still missing somewhere.
  • A %YAML or %TAG directive must come before the first ---. Placing one after a document produces this error too.
  • Windows line endings are fine; a stray form-feed or other control character is not, and will be reported at its position.

Related errors