Skip to content

Instantly share code, notes, and snippets.

@LintangWisesa
Created December 30, 2020 04:46
Show Gist options
  • Save LintangWisesa/af07b9b550c08e5e15f3a71741fb683f to your computer and use it in GitHub Desktop.
Save LintangWisesa/af07b9b550c08e5e15f3a71741fb683f to your computer and use it in GitHub Desktop.
yaml.md

simplinnovation

YAML (YAML Ain't Markup Language)

Video

YAML (YAML Ain't Markup Language) is a human-readable data-serialization language. Serialization is the process of translating a data structure or object state into a format that can be stored, transmitted and reconstructed later. YAML is commonly used for configuration files and in applications where data is being stored or transmitted.

Struktur YAML

  1. Struktur YAML yang valid tersusun atas associative array (pasangan key & value), list (list value) maupun kombinasi antara keduanya.

    • Associative array

      # 1. format YAML lazim
      nama: Andi
      usia: 23
      bb: 56.78
      is_married: True
      
      # 2. dapat pula seperti key-value pair pada umumnya
      {
        nama: Andi,
        usia: 23,
        bb: 56.78,
        is_married: True
      }
    • List

      # 1. format YAML lazim
      - Apel
      - Durian
      - Nangka
      - Semangka
      
      # 2. dapat pula seperti key-value pair pada umumnya
      [Apel, Durian, Nangka, Semangka]
  2. Value dapat berupa scalar (string, integer, float, etc.), boolean (true / false), date maupun timestamp.

  3. Perlu diperhatikan pula tab/indentasi, gunakan tab/indentasi untuk nested key (key yang berada di dalam associative array atau list).

  4. Diperkenankan adanya comments dalam YAML, gunakan tanda pagar (#) untuk membuat komentar.

Contoh valid YAML

  1. Associative Array

    # yaml dari assoc array
    namadepan: Andi
    namatengah: "Susilo"
    namabelakang: 'Raharjo'
    pesan: |
      bla bla bla
      bla bla bla
    pesan2: >
      bla bla bla
      bla bla bla
    usia: 23
    bb: 56.78
    tb: 190
    size: "67"
    is_married: True
    is_working: False
    
    --- # pemisah antar dokumen dalam 1 file/stream
    
    {
      namadepan: Andi,
      namabelakang: Susilo,
      namatengah: Raharjo,
      usia: 23,
      bb: 56.78,
      is_married: False
    }
    
    ... # opsional: tanda sebagai akhir file

  1. List

    # list yaml
    - Andi
    - Budi
    - Caca
    - Deni
    
    ---
    
    [Andi, Deni, Budi, Caca]
    
    ---
    
    - True
    - False
    
    ---
    
    [1, 2, 3, 4.5, 6.7, 9]
    
    ...

  1. Reference

    nilaiA: &A
      nilai: A
      status: Sangat Memuaskan
    nilaiB: &B
      nilai: B
      status: Memuaskan
    nilaiC: &C
      nilai: C
      status: Kurang
    
    Andi: *A # merujuk ke nilaiA
    Budi: *B
    Cici: *C
    Deni: *A

  1. Associative array in list

    [
      {
        nama: Andi,
        usia: 23
      },
      {
        nama: Budi,
        usia: 22
      },
      {
        nama: Cici,
        usia: 28
      }
    ]
    
    ---
    
    - nama: Andi
      usia: 23
    - nama: Budi
      usia: 25
    - nama: Cici
      usia: 28

  1. List in associative array

    {
      students: [Andi, Budi, Cici],
      cars: [Pajero, Brio, Triton, Mobilio]
    }
    
    ---
    
    students:
      - Andi
      - Budi
      - Cici
    cars:
      - Xpander
      - Innova
      - Alphard

🍔 Lintang Wisesa


lintang ymail lintang facebook lintang twitter lintang youtube lintang linkedin lintang github lintang hackster lintang bio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment