Yaml is yet the 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 the 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 a properties file, but yaml has it
yaml and properties extensions support keys and values, and Yaml has extra support for
Arrays and map types
Let’s have an array of objects in a yaml file.
--- - id: 1 name: Franc roles: - admin - hr - id: 2 name: John roles: - admin - finance
It is difficult to represent in a property flat structure. Here is an example of representing an array of objects in a properties file.
id=1 name0=franc roles00=admin roles01=hr id=2 name1=john roles10=admin roles11=finance
As you see above, Properties file keys are repeated 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 the properties file with a 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 keys and values in multiple lines using escape characters with limited support.
Yaml supports full fledge to break a string into multiple lines
It supports two kinds 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-line
key: > Longer string is separated into multiple lines here
properties syntax used in a Java programming language, but you can use it in other programming languages with external libraries.
Where YAML is mostly used by all popular programming languages
yaml vs properties file extension
|Contains key and value pairs||Key and values separated by equal or color|
|Human readable format||Easy to read by humans|
|Supports Integer, Strings, Maps, and Lists||Supports primitive types like strings and numbers|
|Supports hierarchical structure||Supports flat and non-hierarchical structure|
YAML has more superset 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.