Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YAML setting value from another key

How can I set a value in YAML from another key e.g:

example.emails:
     - [email protected]
     - [email protected]
     - [email protected]

swift:
        to_email:   example.emails
like image 982
Ben_hawk Avatar asked Mar 09 '13 14:03

Ben_hawk


People also ask

How do you write a key-value pair in YAML?

As we can see, the format is very simple. Each key is followed by a colon and then the value. We can also use quotation marks ( ' or " ) around the key-value pair if we want to include special characters or whitespace.

Does YAML support variables?

In YAML, you can only define variables with pipeline or action scope. Workspace and project variables need to be defined via the GUI.

What is value in YAML?

The YAML above defines four keys - first_name , last_name , age_years , and home - with their four respective values. Values can be character strings, numeric (integer, floating point, or scientfic representation), Boolean ( true or false ), or more complex nested types (see below).

What is key in YAML?

The key-value is YAML's basic building block. Every item in a YAML document is a member of at least one dictionary. The key is always a string. The value is a scalar so that it can be any datatype. So, as we've already seen, the value can be a string, a number, or another dictionary.


1 Answers

Accepted answer is wrong. It might have worked for the author for app specific reason but it is not supported by YAML specs. The correct way to reuse values in yaml is through something called anchors, like this

x1: &my_anchor
  y: 'my val'
x2:
  <<: *my_anchor
  z: 3

In above, we mark the values in x1 using anchor my_anchor. Then the special syntax <<: *my_anchor tells YAML parser to insert children of the node (in this case y) in the same level. So x2 will now have two children: y and z.

like image 112
Shital Shah Avatar answered Sep 23 '22 01:09

Shital Shah