clj-commons/clj-yaml
provides YAML encoding and
decoding for Clojure via the snakeyaml Java library.
(This is a maintained fork of the original).
(require '[clj-yaml.core :as yaml])
(yaml/generate-string
[{:name "John Smith", :age 33}
{:name "Mary Smith", :age 27}])
"- {name: John Smith, age: 33}\n- {name: Mary Smith, age: 27}\n"
(yaml/parse-string "
- {name: John Smith, age: 33}
- name: Mary Smith
age: 27
")
=> ({:name "John Smith", :age 33}
{:name "Mary Smith", :age 27})
By default, keys are converted to clojure keywords. To prevent this,
add :keywords false
parameters to the parse-string
function:
(yaml/parse-string "
- {name: John Smith}
" :keywords false)
Different flow styles (:auto
, :block
, :flow
) allow customization of how YAML is rendered:
(yaml/generate-string some-data :dumper-options {:flow-style :block})
Use the :indent
(default: 2) and :indicator-indent
(default: 0) options to adjust indentation:
(yaml/generate-string some-data :dumper-options {:indent 6
:indicator-indent 3
:flow-style :block})
=>
todo:
- name: Fix issue
responsible:
name: Rita
:indent
must always be larger than :indicator-indent
. If only 1 higher, the indicator will be on a separate line:
(yaml/generate-string some-data :dumper-options {:indent 2
:indicator-indent 1
:flow-style :block})
=>
todo:
-
name: Fix issue
responsible:
name: Rita
clj-commons/clj-yaml
is available as a Maven artifact from Clojars.
[clj-commons/clj-yaml "0.7.0"]
deps.edn
clj-commons/clj-yaml {:mvn/version "0.7.0"}
$ git clone git://github.com/clj-commons/clj-yaml.git
$ lein deps
$ lein test
$ lein install
Can you improve this documentation? These fine people already did:
tim dixon, Erik Assum, Mark McGranaghan, Marc O'Morain, lance bradley, Odd Andreas Sørsæther, startling, Emile Snyder, Avi Flax, twelve17, Martin Klepsch, Frederic Merizen, Nate Smith & Aaron CrowEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close