public
Created

data.json 0.1.x compatibility shim

  • Download Gist
data_json_0_1_compat.clj
Clojure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
;;; data.json 0.1.x compatibility shim
 
;; Loading this file alongside data.json version 0.2.0 adds
;; definitions which make it compatible with the public API of
;; data.json version 0.1.3.
 
 
;; Copyright (c) Stuart Sierra, 2012. All rights reserved. The use and
;; distribution terms for this software are covered by the Eclipse
;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;; By using this software in any fashion, you are agreeing to be bound
;; by the terms of this license. You must not remove this notice, or
;; any other, from this software.
 
(require 'clojure.data.json)
(in-ns 'clojure.data.json)
 
(defn read-json
"Reads one JSON value from input String or Reader.
If keywordize? is true (default), object keys will be converted to
keywords. If eof-error? is true (default), empty input will throw
an EOFException; if false EOF will return eof-value. "
([input]
(read-json input true true nil))
([input keywordize?]
(read-json input keywordize? true nil))
([input keywordize? eof-error? eof-value]
(let [key-fn (if keywordize? keyword identity)]
(condp instance? input
String
(read-str input
:key-fn key-fn
:eof-error? eof-error?
:eof-value eof-value)
java.io.Reader
(read input
:key-fn key-fn
:eof-error? eof-error?
:eof-value eof-value)))))
 
(defn write-json [x out escape-unicode?]
(write x *out* :escape-unicode escape-unicode?))
 
(defn json-str [x & options]
(apply write-str x options))
 
(defn print-json [x & options]
(apply write x *out* options))
 
(defn pprint-json [x & options]
(apply pprint x options))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.