Are there any libraries which allow parsing and modifying yaml files? I tried circe-yaml
. It converts yaml
to json
and then you parse and modify the json. Then convert the json
back to yaml
. Lot of information is lost in this process. Things get reordered and it’s difficult to get a sense of the changes via diff.
I have used moulting YAML which has many nice features. However, I too had a reordering issue since internally maps are used (enough that I used a hand-rolled parser once when this was too much of a nuisance).
regards,
Siddhartha
I believe that our weePickle library handles YAML as well as a bunch of other formats, but I haven’t played with that aspect myself. Knowing the way weePickle works, it is likely that it preserves order (in general, it tries to avoid building intermediate maps when not necessary), but I can’t say for sure. It’s super-flexible by design, and one can build specialized visitors with the desired semantics, although that’s not trivial…
I’m interested in this question, too, and I’ve come across the following options. However, I have not tried any of them yet, so “buyer beware”:
- SnakeYAML (Bitbucket) - This appears to be the most popular Java API for this purpose. There are Scala wrappers…
- Elegant Scala YAML parsing using SnakeYAML and MoultingYaml · Andrea Baita’s blog (Elegant Scala YAML parsing using SnakeYAML and MoultingYaml · Andrea Baita's blog) - mentions another Scala library, MoultingYAML (GitHub - jcazevedo/moultingyaml: Scala wrapper for SnakeYAML)
- Circe YAML wrapper: YAML parser for circe using SnakeYAML (GitHub - circe/circe-yaml: YAML parser for circe using SnakeYAML)
sounds like this is what I was looking for. I will try this out