Now in the previous video we discussed how we could create key value pairs in Y
AML,
now what I want to do is to talk to you about something known as a raise. So
with that said,
let's get to it. So once again if you go to one of the online tools to validate
your YAML,
what I'm going to do is attempt to write some YAML but there's going to be a
bit of a problem.
Let's see what happens. So I'll start off with my three hyphens for good
practice.
And let's maybe say I want to have a name key and the name can just be John Mc
Govern.
Then I happen to have my age, specify 38. And let's maybe say I want to specify WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Then I happen to have my age, specify 38. And let's maybe say I want to specify
the foods that
I like. So I say foods and then I maybe have the value pizza and I try to add
in more foods, okay.
Let's maybe say sushi but there is a bit of a problem. If I go and I click go
here,
here's us here that map keys must be unique and we actually have a problem at
line five which is
this part right here. This is where we have a duplication in the keys
themselves. So this is
a new discovery. Our keys in YAML must actually be unique at least at the same WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
a new discovery. Our keys in YAML must actually be unique at least at the same
level of indentation.
So the question is what if we have multiple values we want to specify say for
example we have
multiple favorite foods or multiple servers that type of thing. We can't just
keep duplicating
the key itself. So how will we solve this particular problem? Well the answer
is by creating something
known as an array. Sometimes colloquially this might be referred to as a list
object
but the correct terminology with respect to YAML is indeed an array. Now what
an array is going to
do is going to allow us to specify multiple values. Now one thing to note is WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
do is going to allow us to specify multiple values. Now one thing to note is
that we can actually
denote this in two different ways. We can use something known as the inline
syntax. This is going
to make use of square brackets and we can also use something known as the block
format syntax.
This is basically going to make use of hyphens. Now there is no right or wrong
way in which to do
this both types of syntax is absolutely valid but the more common one you're
going to see is indeed
the block format utilizing the hyphens. But I'll show you both just in case. So WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
the block format utilizing the hyphens. But I'll show you both just in case. So
let's maybe say we
have a whole bunch of food that we want to represent. We could just have a food
key and as opposed to
having the value here as pizza we could try say for example the inline format
in fact let me just
zoom in a little bit here. So in fact let's first start with the block format
because that is the
most common. So indented within foods because it's going to belong to the foods
I'm going to say
one two for the spacing and then I'm going to have a hyphen and then after that
hyphen I can
specify the actual value that I want to add in here so I can say pizza if I hit WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
specify the actual value that I want to add in here so I can say pizza if I hit
enter and I do
space space and hyphen again I can add in my second value which would be sushi
and again I
can add in another value let's maybe say carrots carrots are not my favorite
food by the way I'm
just adding in some new values and if I get down here and click go notice this
is valid yaml and
we can see here visually that these three values because of the indentation
here they actually belong
to the food key that in the food folder so to speak. Now like I say we can also
do this using the
inline formatting or the inline syntax let's just delete this and the way we do WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
inline formatting or the inline syntax let's just delete this and the way we do
this is by simply
using square brackets so if we do square brackets here we can just specify all
of the values that
we want and we separate those values out utilizing commas so I could just say
pizza and then a
comma and then add in sushi and then a comma and then again I can add in
carrots and I hit go right
here automatically you'll notice that this particular program has accepted this
is valid yaml but it
did actually format it using the block format indentation nevertheless both WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
did actually format it using the block format indentation nevertheless both
ways are absolutely
valid so in combination with these key values as well as these array objects
you can really
create some very complex and nested data so let's say I wanted to represent all
of the users on my
system now if I happen to have multiple users I would want to have my hyphen to
denote multiple
objects and I could give that user a name so let's say the name is samona and
the next user can be
lalo now maybe we want to add in the user ID for that particular user so let's WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
lalo now maybe we want to add in the user ID for that particular user so let's
maybe say
a one thousand and one for samona and similar for lalo we can have one thousand
and two so now let's
say the next thing that we want to represent where all of the groups that these
users happen to be a
member of now this is going to comprise of multiple entries so what I could do
is I could create a
group's key right here and again and then to within I could have my hyphens so
I can say samona is part
of the samona primary group and let's imagine samona is part of the view group
and let's say
samona is also part of the engineering team similarly with lalo we can have WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
samona is also part of the engineering team similarly with lalo we can have
groups and in
within lalo can be part of the lalo primary group and let's say lalo is not a
member of the view group
but lalo is a member of the design team notice that via the use of my hyphen
ation I'm able to
effectively duplicate say for example the name key here and the name key here
because they're
part of an array and similarly nested within those we can further use those
array objects in this
case here to signify multiple different values for the groups key so let's try WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
case here to signify multiple different values for the groups key so let's try
the validation
We click go as we can see here this indeed is valid yamel.