Now another file format we're going to look at is
JSON, our JavaScript Object Notation.
A really good way to compare both YAML and JSON is to go out to a
website where we can see the difference between YAML and JSON very
easily ourselves. Working now within our browser,
you can see we've navigated to the URL shown on the screen.
From here,
we can see on our left‑hand side of the screen, YAML documentation, and then
seeing how it is output in JSON on the right‑hand side.
Let's go through and clear everything out on our left‑hand side, so you
can see our output now is null. As we go through and put our simple key
value pair, name and fred, we can see in JSON, it's a little bit more
complex because we've got our brace brackets which define our dictionary,
and we've got a list of key value pairs within our main JSON document. As
we move back into our YAML‑side of the window, we can create then a YAML
dictionary.
Now these are relatively easy to write. So we've got items, we
can make sure that we use two spaces to move in, and we can then
have our normal item1, 2, and 3.
So as we then start writing this, this is quite easy to
write, and for humans to read, quite easy to read when we
start looking at the YAML notation.
However, when we look at it in our JSON notation,
it's a little bit more complex.
We can see now that we've got items, and we've got
square brackets defining our list.
Our list items are separated by a comma, as is the list from our simple key
value pair, name and fred. Moving back to our left‑hand side,
we can create then our dictionary.
Remember, JSON starts with the dictionary in there in the brace
brackets, but when we look at it in YAML, again,
these are very easy to create, so simple key value
pairs that are all part of the package.
We know they're part of the package because we're at that
same indent level inside of our package.
Whereas we move across now and take a look inside of our JSON
document, we can see then that we've got our additional brace
brackets defining the extra dictionary that we've got, as well as
the external dictionary we've got with our overriding brace
brackets that define everything.
So JSON is very good as a back‑end system for the software to read, but
for humans to read and write, then it's a lot easier working with YAML.
So when we start looking at items such as Salt and Ansible, we use YAML
to define our state files.
For the moment though, we'll return to our slides so we can summarize what we've seen.