YAML error: did not find expected '-' indicator

A block sequence (a YAML list) is a run of lines that each start with - at the same indentation. The parser was inside such a list and found a line that was neither a new - item nor correctly indented content of the current item. Usually a property of a list item is indented one space too few, or a key that belongs elsewhere sits at the dash column.

Seen as:

  • yaml: line 5: did not find expected '-' indicator
  • error converting YAML to JSON: yaml: line 5: did not find expected '-' indicator
  • (<unknown>): did not find expected '-' indicator while parsing a block collection at line 2 column 3
  • yaml.parser.ParserError: while parsing a block collection expected <block end>, but found '?'
  • YAMLException: bad indentation of a sequence entry (5:4)

Input

Settings

History

Load from URL

Common causes

1. An item property indented one space short

The properties of a list item must line up with the first key after the dash. Here value starts one column left of name, so it belongs to neither the item nor the list.

Before
- name: REGION
 value: "eu-west-1"
After
- name: REGION
  value: "eu-west-1"

2. A key placed at the dash column inside a list

In a GitHub Actions or CI file, writing a key at the same indentation as the dashes ends the list as far as you are concerned, but not for the parser. Move it out to its parent’s level or make it an item.

Before
steps:
  - name: Test
    run: npm test
  name: Deploy
After
name: Deploy
steps:
  - name: Test
    run: npm test

3. A new item written without its dash

Adding an item by copying the properties of the previous one but forgetting - leaves a mapping inside the list. Every item needs its own dash.

Before
ports:
  - containerPort: 80
  containerPort: 443
After
ports:
  - containerPort: 80
  - containerPort: 443

Frequently asked questions

Do list dashes need to be indented under their key?

No. Both “key:\n- item” and “key:\n - item” are valid. What matters is that every dash in the same list sits in the same column and that each item’s properties line up after the dash.

What does PyYAML's "expected <block end>, but found '?'" mean?

It is PyYAML’s wording for the same problem: inside a block collection it expected the list to continue or end and found a mapping key (‘?’) instead.

How can I see the structure the parser is building?

Fix the first error PasteKit reports, then open the Tree view. It shows which keys belong to which list item, which quickly reveals an item that swallowed a sibling’s property.

Related