clj-yaml

Ingy döt Net 2023-09-07T13:08:23.664049Z

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

lread 2023-09-07T13:13:01.735119Z

Hiya Ingy! Are the https://github.com/clj-commons/clj-yaml/blob/master/doc/01-user-guide.adoc#dumper-options not working for you?

Ingy döt Net 2023-09-07T13:26:09.155289Z

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=> 

👍 1
Ingy döt Net 2023-09-07T13:28:35.879009Z

: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 Net 2023-09-07T13:31:12.360879Z

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 Net 2023-09-07T13:31:34.897749Z

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

Ingy döt Net 2023-09-07T13:32:39.596429Z

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

lread 2023-09-07T13:51:03.256209Z

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 Net 2023-09-07T14:00:52.645909Z

yeah don't bother

👍 1
Ingy döt Net 2023-09-07T13:34:26.210579Z

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. 👍

👍 1