Skip to content

Instantly share code, notes, and snippets.

@stuartsierra
Created October 25, 2012 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stuartsierra/3950124 to your computer and use it in GitHub Desktop.
Save stuartsierra/3950124 to your computer and use it in GitHub Desktop.
data.json 0.1.x compatibility shim
;;; 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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment