Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
May 3, 2021 06:27 am GMT

Are we all YAML engineers now?

Photo by Louis Hansel on Unsplash

What is YAML? And how it works?

Recently I switched jobs, and as part of this change, Ive been introduced to a whole new tech stack. RabbitMQ , Java Spring, Docker, etc. (meaning more subjects to write about ). Most of the technologies I use on a daily basis consume YAML as their configuration. In this post, Ill try to illustrate what Ive learned (and from where) while trying to understand this new world.

Learn the YAML waysrc.

It is what it is

YAML stands for Y AML A int M arkup L anguage, originally named Yet Another Markup Language. The name was chosen because it requires much less markup than other traditional languages, such as XML. It distinguishes it as more data-oriented rather than markup-oriented. YAML spec says it better:

YAML (rhymes with camel) is a human-friendly, cross language, Unicode based data serialization language designed around the common native data structures of agile programming languages.

Well, what is it used for?

It has become widespread for writing configuration files because it uses a human-readable, intuitive, and flexible language. It can be used with almost any application that needs to send or store data (and has no code execution capabilitiesSecure?). YAML is a superset of JSON, which means any valid JSON is a valid YAML file. It has several advantages over JSON; it can self-reference, support complex datatypes, embedded block literals, support comments, and more.

JSON VS YAML

Furthermore, Ive recently learned that one of the most common usages for YAML in the java world is an autogenerated code using swagger (API deployment). YAML defines the classes, and swagger generates the code. But that is a separate story for a different post.

How does it work?

The basic building block of YAML documents is a key-value pair. The nesting is based on indentation (similar to Python), making it resistant to delimiter collision. Just keep in mind, whatever you do, DO NOT USE TABS. Yaml hates tabs, and it wont work. Tip: use a YAML linter, whether an online one or a plugin in your IDE.

Writing YAMLsrc

It is insensitive to quotes and brackets, making special characters more easily defined, especially for strings. To better explain the above concepts, you can find below some simple examples, which I found essential to know when starting to use YAML:

Variables are defined using a colon and space :

integer: 17 string: "17" float: 17.0 boolean: Yes

A list or array can be defined using an inline format thats similar to JSON or a conventional block format:

-------- # To Do List in Block Format - Homework - Walk with the dog - Dog should eat homework  -------- # To Do List in Inline Format [Homework, Walk with the dog, Dog should eat homework]

You can denote a string with a | symbol, which keeps newlines , or a > symbol, which folds them:

data: |    Each of these    Newlines    Will be broken up  data: >    This text is    wrapped and will    be formed into    a single paragraph

Do you want to know more? -src

The YAML complete documentation can be found on its official site. It is worth going over to be familiar with it. Also, there are plenty of online tutorials; Ive found this one to be a great source:

To Wrap Up

YAML is a data-oriented language and a superset of JSON that comes with multiple built-in advantages. It became an industry standard for configuration files. But overall, it is human-readable, which makes it easy to use and maintain. Just be gentle with these whitespaces.

YAML -src


Original Link: https://dev.to/dejavo/are-we-all-yaml-engineers-now-538j

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To