gm.ivlad
gm.ivlad

Reputation: 23

Redefining key-value pair in referenced mapping

Wikipedia article https://en.wikipedia.org/wiki/YAML has "sequencer protocols for Laser eye surgery" example which first defines mapping with anchor label &id001 and then refers to the label but redefines one key:

 - step: *id001
    spotSize: 2mm             # redefines just this key, refers rest from &id001

Is this a correct YAML document? Is it possible to override keys this way? This example fails in YAML parsers I could find online.

Upvotes: 0

Views: 220

Answers (1)

Frank.Wu
Frank.Wu

Reputation: 31

You can use "merge" instead of override the key.

- step:
   spotSize: 2mm
   << : *id001

In PyYAML, yaml parser will ignore duplicate keys.

Upvotes: 1

Related Questions