Spaces in YAML keys

Is there a correct way to use spaces in YAML keys? Like

a test: "hello world!" 

or

"a test": "hello world!"

or is it just a bad idea and one should use

a_test: "hello world!"

All of them seem valid in a yaml-Linter, but I didn't find any examples online using spaces in a key.

2

1 Answer

One thing is what is allowed, another is what is human readable.

Spaces are allowed in keys according to the specification and for those you don't need quotes (double or single, each with their own use). It is just a scalar string containing a space.

As for human readability, I tend to think of a and test in a test as not belonging together. That is of course caused by what I am used to, and that e.g. variables in most programming languages cannot have spaces (although my one of my first languages, Algol 68, did allow that). For human readability I would suggest using a_test over "a test" (or 'a test'), but others might have different preferences.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like