GithubHelp home page GithubHelp logo

clj-yaml's Introduction

Deprecation

This library is no longer maintained. An actively developed fork is suggested.

Historical README

clj-yaml provides YAML encoding and decoding for Clojure via the SnakeYAML Java library.

Usage

(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})

Installation

clj-yaml is available as a Maven artifact from Clojars:

:dependencies
  [["clj-yaml" "0.4.0"]
   ...]

Development

$ git clone git://github.com/lancepantz/clj-yaml.git
$ lein deps
$ lein test
$ lein install

clj-yaml's People

Contributors

arohner avatar lancepantz avatar mmcgrana avatar mpenet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

clj-yaml's Issues

serialized !!clojure.lang.Symbol has no content

(clj-yaml.core/generate-string {:x :y :a "b"} :dumper-options {:flow-style :flow})
;= "{x: y, a: b}\n"

(clj-yaml.core/generate-string {:x :y :a "b"} :dumper-options {:flow-style :block})
;= "x: y\na: b\n"

(clj-yaml.core/generate-string {:x :y :a 'b} :dumper-options {:flow-style :flow})
;= "{x: y, a: !!clojure.lang.Symbol {}}\n"

(clj-yaml.core/generate-string {:x :y :a 'b} :dumper-options {:flow-style :block})
;= "x: y\na: !!clojure.lang.Symbol {}\n"

Reflection Warnings

Reflection warning, clj_yaml/core.clj:19 - call to dump can't be resolved.
Reflection warning, clj_yaml/core.clj:34 - call to load can't be resolved.

No license

There's no statement of license in the source tree or documentation. The default license in most countries does not allow for free use.

can deserialize a Set, but can't serialize a Set

;; works:

(def typed-data-yaml "
the-bin: !!binary 0101")

(clj-yaml.core/parse-string typed-data-yaml)
;= {:the-bin #<byte[] [B@61911e64>}

(clj-yaml.core/generate-string
  (clj-yaml.core/parse-string typed-data-yaml)
  :dumper-options {:flow-style :block})
;= "the-bin: !!binary |-\n  0101\n"


;; generate-string creates a sequence instead of a set:

(def set-yaml "
--- !!set
? Mark McGwire
? Sammy Sosa
? Ken Griff")

(clj-yaml.core/parse-string set-yaml)
;= #{"Mark McGwire" "Ken Griff" "Sammy Sosa"}

(clj-yaml.core/generate-string
  (clj-yaml.core/parse-string set-yaml)
  :dumper-options {:flow-style :block})
;= "- Mark McGwire\n- Ken Griff\n- Sammy Sosa\n"

(clj-yaml.core/parse-string
  (clj-yaml.core/generate-string
    (clj-yaml.core/parse-string set-yaml)
    :dumper-options {:flow-style :block}))
;= ("Mark McGwire" "Ken Griff" "Sammy Sosa")

feature request: optional parameters for primitives

Perhaps something like {:native-keywords true :native-symbols true :native-vectors false}

  • With native keywords and symbols:
=>  (println (yaml-dump ['a/b/c :d/e/f (symbol "stuff and/or things") (keyword "other and/or widgets")]))

---
- !!clojure.lang.Symbol
  name: c
  namespace: a/b
- !!clojure.lang.Keyword
  name: f
  namespace: d/e
  sym:
    name: f
    namespace: d/e
- !!clojure.lang.Symbol
  name: or things
  namespace: stuff and
- !!clojure.lang.Keyword
  name: or widgets
  namespace: other and
  sym:
    name: or widgets
    namespace: other and
...
  • With common denominator:
  clojure.lang.Keyword
  (encode [data]
    (.substring (str data) 1))

  clojure.lang.Symbol
  (encode [data]
    (str data))
=> (println (yaml-dump ['a/b/c :d/e/f (symbol "stuff and/or things") (keyword "other and/or widgets")]))

---
- a/b/c
- d/e/f
- stuff and/or things
- other and/or widgets
...

(Encoding style similar to cheshire: https://github.com/dakrone/cheshire/blob/6d78a56929f3cb4e925e2d09617465314d3114ba/src/cheshire/generate.clj#L134 )

Problem with maps using integer keys

(yaml/generate-string {46 "MAYBE" 52 "DEFINITELY"})
"{46: MAYBE, 52: DEFINITELY}\n"

(yaml/parse-string (yaml/generate-string {46 "MAYBE" 52 "DEFINITELY"}))
{nil "DEFINITELY"}

This seems to be legal YAML, and SnakeYAML itself seems to handle it AFAICT.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.