0

I have a unique usecase where I need to read yaml file with anchors and aliases. Update it. Write it back preserving the anchors and aliases.

Example original file:

templates:
  obx: &anch
    series: [5,15]
  series: &series100
    - 100
    - 101
data: 
  ob1:
    series: [10, 20]
  ob2:
    series:
      - 100
      - 200
  obn1: *anch
  obn2: 
    <<: *anch
    series: []
  obn3:
    series: *series100

Want to replace all series here with lets say series: [500].

Desired file:

templates:
  obx: &anch
    series: [500]
  series: &series100
    - 500

data: 
  ob1:
    series: [500]
  ob2:
    series:
      - 500
  obn1: *anch
  obn2: 
    <<: *anch
    series: 500
  obn3:
    series: *series100

I know it can be hard to achieve this using traditional yaml readers and writers like SnakeYaml. I am also okay if there is a way to do it with just regex string update if that is easier to do.

suresh
  • 254
  • 5
  • 9

0 Answers0