Code Beautifier
unexpected end of the stream within a flow collection

Fix "unexpected end of the stream within a flow collection"

A YAML flow collection ([ ] or { }) was opened and never closed. Why the error points at the end of the file, and how to find the missing bracket.

Input that triggers it

tags: [api, internal
owner: platform
Open YAML to JSON 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.

Conversion Mode:
Indent size:
yaml
json

What the error means

YAML has two ways to write a list or a mapping. The block style uses indentation and dashes; the flow style uses JSON-like brackets and braces on a single line: [a, b] or {key: value}. A flow collection must be closed. When the parser opens one and reaches the end of the input without finding the matching ] or }, it reports unexpected end of the stream within a flow collection.

The phrase "end of the stream" is why this error is confusing: it is reported at the last line of the file, however far that is from the actual mistake. In the example, the missing ] is on line one, but the parser happily consumes owner: platform as more list content and only fails when the input runs out.

Why it happens

  • A dropped closing bracket after editing a list inline, typically when an item is added at the end.
  • A line break inside a flow collection. Flow style can span lines, but a following line that looks like a mapping key is swallowed as list content, so the collection never closes where you expect.
  • Mixing styles: starting a list with [ and then continuing with - item lines on the next lines.
  • A quote mismatch inside the brackets, so the closing bracket is read as part of a string.

How to fix it

  1. Paste the document into the converter above. Ignore the reported line; instead, search the file for [ and { and check that each has a closer on the same line.
  2. Add the missing ] or }. In the example, line one becomes tags: [api, internal].
  3. Convert again. The JSON output shows the list as an array, which confirms the collection closed where you intended and that owner is a sibling key, not a list item.

The corrected example:

tags: [api, internal]
owner: platform

For a long list, block style is easier to keep balanced:

tags:
  - api
  - internal
owner: platform

If it still fails

  • Check for an unmatched quote inside the collection. [api, "internal] never closes the string, so the bracket after it is part of the value.
  • If the file is a Kubernetes manifest or a Compose file produced by a template, search the template for the bracket rather than the output.
  • The same underlying problem in JSON produces Unexpected end of JSON input; the fix is the same, and JSON Validator reports the structure it read before the input ran out.

Related errors