How to escape indicator characters (i.e. : or - ) in YAML

danieltahara picture danieltahara · Jul 2, 2012 · Viewed 240.3k times · Source

In a config file, I have a key to which I wish to assign a URL. The problem is that YAML interprets : and - characters as either creating mappings or lists, so it has a problem with the line

url: http://www.example-site.com/

(both because of the colon following http and the hyphen in the middle)

Is there an explicit way to escape ':' and '-' ? Or would it work to just put the whole thing in single quotes and call it a day?

Answer

Ry- picture Ry- · Jul 2, 2012

Quotes:

"url: http://www.example-site.com/"

To clarify, I meant “quote the value” and originally thought the entire thing was the value. If http://www.example-site.com/ is the value, just quote it like so:

url: "http://www.example-site.com/"