Created
May 6, 2022 16:10
-
-
Save tyhawkins/c6383da17332921a087fe3338a580d81 to your computer and use it in GitHub Desktop.
Yaml tips and tricks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## YAML Anchors and tags | |
ingress_one: | |
annotations: &annotations | |
annotation-one: "true" | |
annotation-two: "false" | |
annotation-three: "false" | |
ingress_two: | |
annotations: *annotations | |
ingress_three: | |
annotations: | |
<<: *annotations | |
annotation-three: "true" | |
host: &host www.example.com | |
tls: | |
- host: *host | |
## Type and explicit type declarations | |
specific_type: | |
implicit_string: This space for rent | |
tagged_string: !!str true | |
bool: !!bool true | |
int: !!int 123456789 | |
float_infinity: !!float .inf | |
float_positive: !!float 2.3e4 | |
sequence: !!seq | |
- item one | |
- true | |
- 123456789 | |
map: !!map | |
foo: bar | |
bar: foo | |
fail: "" | |
null_value: !!null null | |
## JSON Equivalence | |
object1: | |
key1: value1 | |
key2: value2 | |
object2: {"key1": "value1", "key2": "value2"} | |
object3: {"thing": { "thing2": "other thing"}, "foo": { "is_bar": true}} | |
array1: | |
- thing1 | |
- thing2 | |
array2: ["thing1", "thing2", true, 0, 0.0] | |
## Multiline strings | |
file1.txt: | | |
This is an example file. | |
It has newlines in it. | |
It also ends with an implicit newline. | |
file2.txt: |- | |
This is an example file. | |
It has newlines in it. | |
It does not end with an implicit newline. | |
file3.txt: > | |
This is an example file. | |
Newlines are converted to spaces. | |
It ends with an implicit space. | |
file4.txt: >- | |
This is an example file. | |
Newlines are converted to spaces. | |
It does not have an implicit space at the end. | |
File1: | |
This is an example file. | |
It has newlines in it. | |
It also ends with an implicit newline. | |
File2: | |
This is an example file. | |
It has newlines in it. | |
It does not end with an implicit newline. | |
File3: | |
This is an example file. Newlines are converted to spaces. It ends with an implicit space. | |
File4: | |
This is an example file. Newlines are converted to spaces. It does not have an implicit space at the end. | |
see_more: https://yaml-multiline.info/ | |
## Selective quoting of keys to increase readability | |
object: | |
"subobject1": | |
key: okay | |
foo: bar | |
one: two | |
array: | |
- one | |
- two | |
json: {"foo": "bar"} | |
"subobject2": | |
key: okay | |
foo: bar | |
one: two | |
array: | |
- one | |
- two | |
json: {"foo": "bar"} | |
"subobject3": | |
key: okay | |
foo: bar | |
one: two | |
array: | |
- one | |
- two | |
json: {"foo": "bar"} | |
"subobject4": | |
key: okay | |
foo: bar | |
one: two | |
array: | |
- one | |
- two | |
json: {"foo": "bar"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment