babashka / json

JSON abstraction library
MIT License
30 stars 2 forks source link

babashka.json

Clojars Project

This library provides an abstraction over several JSON implementations, covering the most common scripting use cases:

The idea of this library is that you can use it in both JVM Clojure and babashka, without having to write code to dispatch between your choice of JVM Clojure library and babashka's built-in cheshire.core library. Instead of this:

#?(:bb (cheshire.core/parse-string ...)
   :clj (clojure.data.json/read-str ...))

you can now write:

(babashka.json/read-str ...)

instead, while still choosing your preferred implementation on the JVM.

On the JVM, this library uses whatever is on your classpath, in the following order:

You can force an implementation by setting the babashka.json.provider JVM system property before loading this library to:

For convenience this library depends on one JSON implementation, org.clojure/data.json, so you don't have to include another dependency. If you don't want this dependency on your classpath, you can use:

:exclusions [org.clojure/data.json]

More implementations will be added and contributions are welcome.

Planned:

If you are the author of one of the planned libraries, feel free to provide a PR as well.

At some point this library will be included in babashka, but for now you can use it as a library in bb.edn.