YAML: Do I need quotes for strings in YAML?

I am trying to write a YAML dictionary for internationalisation of a Rails project. I am a little confused though, as in some files I see strings in double-quotes and in some without. A few points to consider:

  • example 1 – all strings use double quotes;
  • example 2 – no strings (except the last two) use quotes;
  • the YAML cookbook says: Enclosing strings in double quotes allows you to use escaping to represent ASCII and Unicode characters. Does this mean I need to use double quotes only when I want to escape some characters? If yes – why do they use double quotes everywhere in the first example – only for the sake of unity / stylistic reasons?
  • the last two lines of example 2 use ! – the non-specific tag, while the last two lines of the first example don’t – and they both work.

My question is: what are the rules for using the different types of quotes in YAML?

Could it be said that:

  • in general, you don’t need quotes;
  • if you want to escape characters use double quotes;
  • use ! with single quotes, when… ?!?

7 s
7

Leave a Comment