mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-05-07 07:18:31 +00:00
Merge pull request #2006 from jargnar/more-yaml-stuff
Add more complex key examples, and an example of inheritance
This commit is contained in:
commit
2b2a4a9ae0
@ -3,6 +3,7 @@ language: yaml
|
|||||||
filename: learnyaml.yaml
|
filename: learnyaml.yaml
|
||||||
contributors:
|
contributors:
|
||||||
- ["Adam Brenecki", "https://github.com/adambrenecki"]
|
- ["Adam Brenecki", "https://github.com/adambrenecki"]
|
||||||
|
- ["Suhas SG", "https://github.com/jargnar"]
|
||||||
---
|
---
|
||||||
|
|
||||||
YAML is a data serialisation language designed to be directly writable and
|
YAML is a data serialisation language designed to be directly writable and
|
||||||
@ -66,14 +67,19 @@ a_nested_map:
|
|||||||
# Maps don't have to have string keys.
|
# Maps don't have to have string keys.
|
||||||
0.25: a float key
|
0.25: a float key
|
||||||
|
|
||||||
# Keys can also be multi-line objects, using ? to indicate the start of a key.
|
# Keys can also be complex, like multi-line objects
|
||||||
|
# We use ? followed by a space to indicate the start of a complex key.
|
||||||
? |
|
? |
|
||||||
This is a key
|
This is a key
|
||||||
that has multiple lines
|
that has multiple lines
|
||||||
: and this is its value
|
: and this is its value
|
||||||
|
|
||||||
# YAML also allows collection types in keys, but many programming languages
|
# YAML also allows mapping between sequences with the complex key syntax
|
||||||
# will complain.
|
# Some language parsers might complain
|
||||||
|
# An example
|
||||||
|
? - Manchester United
|
||||||
|
- Real Madrid
|
||||||
|
: [ 2001-01-01, 2002-02-02 ]
|
||||||
|
|
||||||
# Sequences (equivalent to lists or arrays) look like this:
|
# Sequences (equivalent to lists or arrays) look like this:
|
||||||
a_sequence:
|
a_sequence:
|
||||||
@ -101,12 +107,31 @@ json_seq: [3, 2, 1, "takeoff"]
|
|||||||
anchored_content: &anchor_name This string will appear as the value of two keys.
|
anchored_content: &anchor_name This string will appear as the value of two keys.
|
||||||
other_anchor: *anchor_name
|
other_anchor: *anchor_name
|
||||||
|
|
||||||
|
# Anchors can be used to duplicate/inherit properties
|
||||||
|
base: &base
|
||||||
|
name: Everyone has same name
|
||||||
|
|
||||||
|
foo: &foo
|
||||||
|
<<: *base
|
||||||
|
age: 10
|
||||||
|
|
||||||
|
bar: &bar
|
||||||
|
<<: *base
|
||||||
|
age: 20
|
||||||
|
|
||||||
|
# foo and bar would also have name: Everyone has same name
|
||||||
|
|
||||||
# YAML also has tags, which you can use to explicitly declare types.
|
# YAML also has tags, which you can use to explicitly declare types.
|
||||||
explicit_string: !!str 0.5
|
explicit_string: !!str 0.5
|
||||||
# Some parsers implement language specific tags, like this one for Python's
|
# Some parsers implement language specific tags, like this one for Python's
|
||||||
# complex number type.
|
# complex number type.
|
||||||
python_complex_number: !!python/complex 1+2j
|
python_complex_number: !!python/complex 1+2j
|
||||||
|
|
||||||
|
# We can also use yaml complex keys with language specific tags
|
||||||
|
? !!python/tuple [5, 7]
|
||||||
|
: Fifty Seven
|
||||||
|
# Would be {(5, 7): 'Fifty Seven'} in python
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# EXTRA YAML TYPES #
|
# EXTRA YAML TYPES #
|
||||||
####################
|
####################
|
||||||
|
Loading…
Reference in New Issue
Block a user