Yaml is yet market language for data serialization format
properties files are used for representing key and value simple values.
Both are used for configuration files for deployment and application configuration.
For example, Spring boot supports application.yaml and application.properties file for configuration settings
But there are some differences in yaml and properties extension
Difference between .yaml and .yml file extension
- No Maps or lists in properties file, but yaml has it
yaml and properties extensions supports key and values and Yaml has extra support for
Arrays and map types
Let’s have a arrays of objects in yaml file
--- - id: 1 name: Franc roles: - admin - hr - id: 2 name: John roles: - admin - finance
It is very difficult to represent in properties flat structure. Here is an example for representing array of objects in properties file.
id=1 name0=franc roles00=admin roles01=hr id=2 name1=john roles10=admin roles11=finance
As you see above, Properties files keys are repeated and and readability is not good
- hierarchical structure vs non hierarchical structure
profile: qa: url: http://qa.com database: appqa prod: url: http://prod.com database: appprod
The same can be configured in properties file with flat structure
profile.qa.url=http://qa.com profile.qa.database=appqa profile.prod.url=http://prod.com profile.prod.url=appprod
- Break multiple String
Properties files are supported to break key and values in multiple lines using escape character with limited support.
Yaml supports full fledge to break string into multiple lines
It supports two kind of syntaxes literal and folder block to split into multiple lines
We have a string
key: 'Longer string is separated into multiple lines here' here is literal styles using pipe(|) operator ```YAML key: | Longer string is separated into multiple lines here
Folder style syntax to break into multi lines
key: > Longer string is separated into multiple lines here
properties syntax is used in java programming language, but you can use it in other programming languages with external libraries.
Where as YAML is mostly used by all popular programming languages
yaml vs properties file extension
|Contains key and value pairs||Key and values separted by equal or color|
|Human readable format||Easy to read by humans|
|Supports Integer,Strings,Maps,Lists||Supports primitive types like strings and numbers|
|Supports hierarchical structure||Supports flat and non hierarchical structure|
YAML has more super set features when compared with properties in features like types(List and Map), type safety and hierarchical structure.
It is always best to choose yaml with wider programming language support