nightis
nightis

Reputation: 25

YAML error- expected <'document start'>, but found <'block mapping start'>

A Bash command I'm running is supposed to update a YAML file.

The YAML file is as follows-

---
[conf]

users:
  - mitchell

I get the error-

ERROR! Syntax Error while loading YAML.
  expected '<document start>', but found '<block mapping start>'

The offending line appears to be:

users:
^ here

What should I do?

Thanks a lot!

Upvotes: 0

Views: 11087

Answers (1)

flyx
flyx

Reputation: 39638

[conf] in YAML is a flow sequence consisting of a sequence start indicator ([), one item (the scalar conf), and a sequence end indicator (]).

Since a YAML document can only have one root node, the document is finished after ]. A YAML file allows you to have multiple documents in it, separated by --- (and optionally ...). So for example, this would be valid YAML:

---
[conf]
---
users:
  - mitchell

Since a separator is missing, your YAML parser complains that it expected the start of a new document but found more content in the current document whose root node has already been closed.

Chances are that you expect [conf] to be a special syntax for a section like e.g. in INI files. But it isn't. To put the following content into a section, you'd simply do

conf:
  users:
    - mitchell

Upvotes: 3

Related Questions