Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to escape space comma doublequotes from yaml file

Tags:

yaml

I want to escape comma, space & double quotes from a YAML file.
How can I do that?

like image 889
Gowrisankar M Avatar asked Oct 19 '25 16:10

Gowrisankar M


1 Answers

There are multiple ways to include those three characters in a YAML scalar, but if you want to do so using escaping, you have to realise you only can escape the double quote and not the comma or space.

To do so you need to use a double quoted scalar:

"this is a YAML document, with embedded space, comma and escaped double quote (\")"

If however your spaces are not at the beginning or the end, and your double quote not at the beginning of the scalar, you don't need quotes at all. The above is equivalent to the plain scalar:

this is a YAML document, with embedded space, comma and escaped double quote (")

Plain scalars have some restrictions, e.g. you cannot have any of the special characters that start special constructs (among others {, [, & and *) at the beginning, something that looks like the beginning of a comment ( space + # ) or the value indicator (: followed by space) in the middle of plain scalar.

There are also single quoted and block style literal and folded scalars with their own rules.

If unsure I recommend using double quotes. If you load-then-dump that YAML, your library is likely to remove any superfluous quoting the first time you do so.

like image 91
Anthon Avatar answered Oct 24 '25 20:10

Anthon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!