Thursday, December 10, 2020

YAML - an intro

 YAML Tutorial - Yet Another Markup Language.

YAML is indentation-based markup language. The main purpose of this language is easy to read and write. JSON and YAML are very similar but JSON uses brackets and braces.
---
  bird: "sky is where he plays"
  fish: "Ocean is where he plays"
  pi: 3.1415
  rice: 3
  fruits:
    - apple
    - banana
    - straberry
    - "Pine Apple"
  party-supply:
    fruits: four
    rice: 3
    tomato: 25
    chicken:
      count: 5
      location: "Bob's Poltry"

YAML syntax

- This file starts with three dashes(---), which indicates that the start of new YAML document.
- Next we see, a key-value pair. bird is a key pointing to sky is where he plays.
Note: Newline indicates the end of a field and indentation can be one ormore spaces and no tab.

Here, we see different data types.
bird and fish are strings.
pi is integer
rice is 3 bags an integer.
strings can be enclosed in single, double or no quotes.
fruits has 4 values defined by -.
Indentation is very importand in yaml. We intended with two space and hyphen and a space.
You can not use tab. This is how you can nexted the values in YAML.

Now, look at the values on party supply. we see 4 intended values (element). We see it as a dictionary which contains one string value, two numerical value and another dictionary (chicken).

We see values are nexted and mix.

Comments:
YAML comments begin with a # (hash) sign and can appear anywehre in the document.
ANything after the # sign will be ignored.

- - -
# This document contains info about birds
  bird: "Fly high"



YAML Datatypes
---------------
Values in YAML key-value pairs are scalar. Its a good practice to enclose strings in quotes and leave the number unquoted.

- key is always string and the value is a scalar so it can be of any data type such as string, number or dictionary.


Numeric types
YAML supports different types of numeric data types. The number (integer) can be of decimal, hexadecimal or octal.

---
  serial-number: 123456
  student-id: 8976567
  bar-code: F2AA215


Strings
YAML strings are unicode.
---
  greet: "Good Morning"

Note: \ - escape sequence.
\n - new line. if you want \ on your return value, do not use double quote.

---
  greet: "Good Morning \n"
  bye: Have a great day \n


You can specify multiline value using fold (greater than sign)

  inst: >
    Please note: user must have admin access to
    the system and enough space on the disk.
    Please review before proceed ....

The above lines will be a single line. If you want the way it is written, use pipe(|) instead of fold (>).


Nulls





Scalars: scalars are ordinary values: numbers, strings, booleans. YAML syntax also allows unquoted string values for convenience. suc as player: Peter Johnson

number-value: 25
floating-point-value: 3.1415
boolean-value: true
string-value: 'John'

Lists and Dictionaries:
Lists are collections of elements:

players:
 - John
 - Mary
 - Peter
 - Bill

Every element of the list is indented and starts with a dash and a space.

Dictionaries are collections of key: value mappings. All keys are case-sensitive.









 from different sources....

No comments:

Post a Comment

Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...