Saturday, 2 June 2018

Basic data types in YAML

YAML support 3 basic data types.
a.   Scalars: Numbers, Strings, Booleans
b.   Sequences: Arrays, Lists
c.   Mappings: Hashes, Dictionaries

Scalar
Scalar represent the primitives in programming languages. For example, a scalar can be a string, integer, double, boolean.

Example
id: 1
firstName: "Krishna"
lastName: "Gurram"

Sequences
Sequences represent list (or) array of items. Here item can be an object (or) a scalar.

Example
---
- id: 1
  firstName: "Krishna"
  lastName: "Gurram"
- id: 1
  firstName: "Chamu"
  lastName: "KB"


Above example represents list of employee objects.

Mappings
Mappings are used to represent hashes, dictionaries.

Example
A map of employees (where key is the id of the employee and value is the employee object) is represented like below.
---
1:
  id: 1
  firstName: "Krishna"
  lastName: "Gurram"
2:
  id: 1
  firstName: "Chamu"
  lastName: "KB"

Above information is rendered like below in Eclipse.





Previous                                                 Next                                                 Home

No comments:

Post a Comment