Is there a library in a JVM language that allows me to parse an existing YAML document, accomplish a small modification in the file and dump it as another file such as existing comments are preserved?
-
No responses in 6 months. Do you insist specifically on a Java library, or will any tool that can do what you ask be useful?– Ira BaxterApr 3, 2016 at 4:44
-
In fact a library in any JVM language will do it (edited the question to reflect that). I would like this to be part of an existing tool-chain already written in Java.– SergioApr 3, 2016 at 12:18
1 Answer
As I understand it Jython runs on the JVM, with that you should be able to use ruamel.yaml
¹:
$ python
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.7.0_111
Type "help", "copyright", "credits" or "license" for more information.
>>> import ruamel.yaml
>>> yaml = ruamel.yaml.YAML()
>>> data = yaml.load("""\
... a:
... - elem1 # not very insteresting
... - elem2 # more of the same
... b:
... - 42
... c: {key: value} # does it work?
... """)
>>> import sys
>>> yaml.dump(data, sys.stdout)
a:
- elem1 # not very insteresting
- elem2 # more of the same
b:
- 42
c: {key: value} # does it work?
>>> exit()
$
¹ Disclaimer: I am the author of that package.
-
-
I have no idea what Maven is, only heard about it by name. I am not sure it is appropriate here, but you could consider asking this as a full-fledged question to get some more people's notice.– AnthonSep 6, 2017 at 4:42