I have YMAL files, using groovy I want to read and modify one element value, then write it into another file.
Playing with this code, trying to modify first filevalue from TopClass.py to changeclass.py. But its not modifying the value.
import org.yaml.snakeyaml.Yaml
class Test{
def static main(args){
Yaml yaml = new Yaml()
def Map map = (Map) yaml.load(data)
println map.Stack.file[0]
map.Stack.file[0]='changeclass.py'
println map.Stack.file[0]
}
def static String data="""
Date: 2001-11-23 15:03:17 -5
User: ed
Fatal:
Unknown variable "bar"
Stack:
- file: TopClass.py
line: 23
code: |
x = MoreObject("345\\n")
- file: MoreClass.py
line: 58
code: |-
foo = bar
"""
Is there sample groovy code to read the YAML file and modify and write it into file?
Thanks SR