Skip to content

Instantly share code, notes, and snippets.

@yarikoptic
Created October 22, 2018 22:41
Show Gist options
  • Save yarikoptic/da5a4f77ecf9d2d5ad86de7e070fe64b to your computer and use it in GitHub Desktop.
Save yarikoptic/da5a4f77ecf9d2d5ad86de7e070fe64b to your computer and use it in GitHub Desktop.
# An example from https://en.wikipedia.org/wiki/YAML#Advanced_components
# pretty printed as .json after "expansion":
$> cat /tmp/sample.yaml
# sequencer protocols for Laser eye surgery
---
- step: &id001 # defines anchor label &id001
instrument: Lasik 2000
pulseEnergy: 5.4
pulseDuration: 12
repetition: 1000
spotSize: 1mm
- step: &id002
instrument: Lasik 2000
pulseEnergy: 5.0
pulseDuration: 10
repetition: 500
spotSize: 2mm
- step: *id001 # refers to the first step (with anchor &id001)
- step: *id002 # refers to the second step
- step:
<<: *id001
spotSize: 2mm # redefines just this key, refers rest from &id001
- step: *id002
$> python -c 'import yaml, json; print(json.dumps(yaml.load(open("/tmp/sample.yaml")), indent=2))'
[
{
"step": {
"pulseEnergy": 5.4,
"instrument": "Lasik 2000",
"repetition": 1000,
"spotSize": "1mm",
"pulseDuration": 12
}
},
{
"step": {
"pulseEnergy": 5.0,
"instrument": "Lasik 2000",
"repetition": 500,
"spotSize": "2mm",
"pulseDuration": 10
}
},
{
"step": {
"pulseEnergy": 5.4,
"instrument": "Lasik 2000",
"repetition": 1000,
"spotSize": "1mm",
"pulseDuration": 12
}
},
{
"step": {
"pulseEnergy": 5.0,
"instrument": "Lasik 2000",
"repetition": 500,
"spotSize": "2mm",
"pulseDuration": 10
}
},
{
"step": {
"pulseEnergy": 5.4,
"instrument": "Lasik 2000",
"repetition": 1000,
"spotSize": "2mm",
"pulseDuration": 12
}
},
{
"step": {
"pulseEnergy": 5.0,
"instrument": "Lasik 2000",
"repetition": 500,
"spotSize": "2mm",
"pulseDuration": 10
}
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment