Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question about the yaml sequences indent #779

Open
chenzhiwei opened this issue Sep 8, 2021 · 4 comments
Open

question about the yaml sequences indent #779

chenzhiwei opened this issue Sep 8, 2021 · 4 comments

Comments

@chenzhiwei
Copy link

When marshal from an object, this library will generate sequences in following format:

--- m dump:
a: Easy!
b:
  c: 2
  d:
  - 3
  - 4

But according to yaml spec: https://yaml.org/spec/1.2/#id2797382

The format seems to be:

--- m dump:
a: Easy!
b:
  c: 2
  d:
    - 3
    - 4

Is there any background on this?

@perlpunk
Copy link

perlpunk commented Sep 8, 2021

Both are valid, and you will also find examples like your first in the spec.
Quote under https://yaml.org/spec/1.2/#id2799181 :

Since people perceive the “-” indicator as indentation, nested block sequences may be indented by one less space to compensate

@chenzhiwei
Copy link
Author

@robin-wayve
Copy link

The latest YAML spec does seem to give the un-indented as its canonical example (though it used to be indented): https://yaml.org/spec/1.2.2/#21-collections

@seh
Copy link

seh commented Mar 2, 2023

See my google/yamlfmt#87 (comment) in google/yamlfmt#87 for more detail on the specification's allowance for both styles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants