Fork me on GitHub
#clj-yaml
<
2023-09-07
>
Ingy döt Net13:09:23

I'm playing around with clj-yaml. I'm not seeing how to 'dump' a collection value to a block style.

Ingy döt Net13:09:09

Heh. Should have read docs first I guess.

user=> (defn load [s] (yaml/parse-string s))
#'user/load
user=> (defn dump [o] (yaml/generate-string o :dumper-options {:flow-style :block}))
#'user/dump
user=> (->> {"a" 1, :b 2} dump load dump print)
a: 1
b: 2
nil
user=> 

👍 2
Ingy döt Net13:09:35

:dumper-options {:flow-style :block} is an unfortunate naming choice better as :coll-style :block yaml collections have 2 styles: block and flow. "flow style" makes no sense in a yaml context.

Ingy döt Net13:09:12

but there's a lot of unfortunate choices in this lib wrt yaml vocabulary (which many implementors seem to not learn). I think it goes to show that the yaml spec is not used so much by implementors except for reference on edge cases.

Ingy döt Net13:09:34

btw, this doesn't bother me much. just pointing it out.

Ingy döt Net13:09:39

I'm hoping to make a reference implementation in clojure eventually.

lread13:09:03

This was probably just picked up from https://www.javadoc.io/doc/org.yaml/snakeyaml/latest/org/yaml/snakeyaml/DumperOptions.FlowStyle.html. I suppose we could make :coll-style be a synonym for :flow-style . And update docs to describe :coll-style. But... maybe this would only really eat at a person who wrote the YAML spec?

Ingy döt Net14:09:52

yeah don't bother

👍 2
Ingy döt Net13:09:26

user=> (defn load [s] (yaml/parse-string s))
#'user/load
user=> (defn dump [o] (yaml/generate-string o :dumper-options {:flow-style :block}))
#'user/dump
user=> (-> {{"a" nil} 1, [:b] 2} dump load dump print)
? a: null
: 1
? - b
: 2
nil
is what I wanted to check. clj-yaml supporting collection keys. 👍

👍 2