-
Lyhyt johdatus YAML-formaattiin
Perustaso
Tarvitset vain perustason tietoteknistä osaamista. On hyödyllistä tietää, miten XML tai JSON toimii.
Lyhyt johdanto YAMLiin
YAMLia käytetään avain-arvo-kuvausten ja taulukoiden kuvaamiseen. YAML-tiedostot tunnistetaan
tiedostopäätteestä .yml tai .yaml.
YAML-aineisto voi olla
- arvo
- taulukko
tai
- sanakirja
tai
- YAML-aineisto
key:
- value 1
- another key:
yet another key: value 2
another key 2:
- more values
this keys value is also an array:
- but indentation is not necessary here
Arvoja voidaan syöttää usealle riville käyttäen merkkiä >:
key: >
Here's a value that is written over multiple lines
but is actually still considered a single line until now.
Placing double newline here will result in newline in the actual data.
Sanatarkka tyyli on tuettu merkillä |:
YAML vs JSON
YAML on JSONin (JavaScript Object Notation) yläsarja. Siten
{
"key": [
{
"value 1": {
"another key": {
"yet another key": "value 2"
},
"another key 2": [
"more values"
],
"this keys value is also an array": ["but indentation is not necessary here"]
}
}
]
}
on myös kelvollista YAMLia. Yleisesti ottaen YAML on tiiviimpää kuin JSON:
key:
- value 1:
another key:
yet another key: value 2
another key 2:
- more values
this keys value is also an array:
- but indentation is not necessary here
yq-komentorivityökalu
yq on hyödyllinen työkalu yamlin käsittelyyn. Sen voi asentaa käyttäen pip:
$ pip show yq
Name: yq
Version: 3.0.2
Summary: Command-line YAML/XML processor - jq wrapper for YAML/XML documents
Home-page: https://github.com/kislyuk/yq
Author: Andrey Kislyuk
Author-email: kislyuk@gmail.com
License: Apache Software License
Location: /home/jtahir/Documents/csc-stuff/osclient/lib/python3.6/site-packages
Requires: argcomplete, PyYAML, toml, xmltodict
Required-by:
yq on jq-wrapperi, mikä tarkoittaa, että se muuntaa yaml-syötteen jsoniksi ja välittää sitten käsittelyn jq:lle. Tästä syystä sen syntaksi on sama kuin jq:n. Alla olevassa esimerkissä .data.WebHookSecretKey:n arvo haetaan raakamuodossa (ilman lainausmerkkejä):