DEV Community

Cover image for YAML Tutorial | Using YAML With Python | PyYAML

YAML Tutorial | Using YAML With Python | PyYAML

Tharun Shiv on May 13, 2020

In this Article (Click to skip to that topic): YAML: What is it? Why do you need YAML? How to use PyYAML to use YAML Files? Advantages of using Y...
Collapse
 
chandrika56 profile image
Jaya chandrika reddy

Which do you think is more used in the Industry? YAML vs JSON

Collapse
 
developertharun profile image
Tharun Shiv

As far as I've noticed, JSON is used in places where the data transfer takes place , and the data is parsed, and the user doesn't manually deal with it.
YAML files are used when user deals with providing inputs or configuration.

See the main advantage of YAML is readability. So the user is less prone to errors like missing a comma or missing a curly bracket. 🙂

Collapse
 
nicolasini profile image
Nico S___

JSON is used for anything API related. Any payload of data transferred between servers, clients, or any other API is very likely to be JSON, unless its XML
YAML is generally used for configuration purposes, although JSON is quite popular for that purpose too.

Collapse
 
developertharun profile image
Tharun Shiv

Yes, that's on point. Thanks 🙂

Collapse
 
reactifystudio profile image
Reactify

JSON. But for DevOps you will need yaml

Collapse
 
baso53 profile image
Sebastijan Grabar • Edited

I absolutely hate YAML. I thought it was only going to be like that only when I started using it, that it would get better with time, but it really hasn't.

My personal opinion:

  • isn't more readable than JSON
  • editor support is an abomination (VS Code and IntelliJ), it never gets the indentation right
  • extremely beginner unfriendly, I bet no one who is looking at YAML for the first won't be sure what is the syntax for what
  • a looot of stuff is valid YAML and there are many ways to write the same things (arrays, I'm looking at you), which again, leads to confusion
  • the YAML spec is HUGE and it contains the whole JSON spec inside of it, which again, just leads to confusion
Collapse
 
nicolasini profile image
Nico S___

I agree with you in the points you dislike. They are definitely an issue.
However, it is more readable than JSON for non-developers. And sometimes that is more important.

Collapse
 
developertharun profile image
Tharun Shiv

Yes Nico. You just give them a template and they will easily fill it in, in case of YAML.

Collapse
 
developertharun profile image
Tharun Shiv

Thanks for sharing your perspective Sebastijan. 🙂

Collapse
 
reactifystudio profile image
Reactify • Edited

Me too.
I find it's indentation poor. Curly braces are works for me. I can easily follow the nesting 💯

Collapse
 
bnorikane profile image
Bruce N Norikane

Excellent explanation of how YAML is used! Your example makes everything very clear.
Thanks

Collapse
 
developertharun profile image
Tharun Shiv

Thanks a lot Bruce! This motivates me to write more... 🙂

Collapse
 
reactifystudio profile image
Reactify • Edited

I don't think it's readable than JSON.
I find it hard to follow. Due to lack of curly braces. I dislike indentation poor when nesting.