Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove '---' on top of a YAML file?

Tags:

ruby

yaml

hash

I am modifying a YAML file in Ruby. After I write back the modified YAML, I see a --- added on top of the file. How is this getting added and how do I get rid of it?

like image 905
Ava Avatar asked Jan 21 '14 07:01

Ava


People also ask

How do I delete content of YAML file?

This uses yq from https://kislyuk.github.io/yq/ to delete the top-level /image-content section from the YAML document using the del() command. Redirect this to a new file if you want to save it, or use the --in-place option to do in-place editing (after testing without that option first, of course).

What are the 3 dashes in YAML?

The file starts with three dashes. These dashes indicate the start of a new YAML document. YAML supports multiple documents, and compliant parsers will recognize each set of dashes as the beginning of a new one.

Does YAML have to start with three dashes?

YAML uses three dashes (“---”) to separate directives from document content. This also serves to signal the start of a document if no directives are present. Also, I tried a sample without --- and understood that it is not mandatory to have them.

What does greater than mean in YAML?

these lines will be indented by 4 spaces. The greater than sign notation, also referred to as “folded block”: folded: > This block of text will be the value of 'folded', but this. time, all newlines will be replaced with a single space. Blank lines, like above, are converted to a newline character.


1 Answers

YAML spec says:

YAML uses three dashes (“---”) to separate directives from document content. This also serves to signal the start of a document if no directives are present.

Example:

# Ranking of 1998 home runs --- - Mark McGwire - Sammy Sosa - Ken Griffey  # Team ranking --- - Chicago Cubs - St Louis Cardinals 

So if you have multiple documents per YAML file, you have to separate them by three dashes. If you only have one document, you can remove/omit it (I never had a problem with YAML in ruby if three-dashes was missing). The reason why it's added when you yamlify your object is that, I guess, the dumper is written "by the spec" and doesn't care to implement such "shortcuts" (omit three-dashes when it's only one document).

like image 121
Sergio Tulentsev Avatar answered Sep 22 '22 09:09

Sergio Tulentsev