API for json.write
- ()
by Stuart Sierra
clojure-contrib is now deprecated
clojure-contrib is no longer being developed or maintained.
Rather than a single, monolithic, contributions library, Clojure now has
a set of separate libraries for each unit of functionality. The libraries
are in the Clojure GitHub organization at
https://github.com/clojure.
API documentation of the libraries can be found at
https://clojure.github.io.
If you're looking for a specific function or namespace from the old
clojure-contrib, see
"Where Did Clojure.Contrib Go".
Full namespace name:
clojure.contrib.json.write
Overview
JavaScript Object Notation (JSON) generator.
This library will generate JSON from the following types:
* nil
* all primitives (Boolean, Byte, Short, Integer, Long, Float, Double)
* String (actually any CharSequence)
* java.util.Map (including Clojure maps)
* java.util.Collection (including Clojure vectors, lists, and sets)
* Java arrays
You can extend this library to handle new types by adding methods to
print-json.
This library does NOT attempt to preserve round-trip equality between
JSON and Clojure data types. That is, if you write a JSON string with
this library, then read it back with clojure.contrib.json.read, you
won't necessarily get the exact same data structure. For example,
Clojure sets are written as JSON arrays, which will be read back as
Clojure vectors.
If you want indented output, try the clojure-json library at
http://github.com/danlarkin/clojure-json
This implementation attempts to follow the description of JSON at
<http://json.org/>. Maps become JSON objects, all other collections
become JSON arrays. JSON object keys are always converted to strings.
Within strings, all non-ASCII characters are hexadecimal escaped.
See also:
JSON Home Page
Public Variables and Functions
json-str
function
This library, clojure-contrib, is deprecated. See here for more information.
Usage: (json-str x)
Converts x to a JSON-formatted string.
Source
print-json
multimethod
This library, clojure-contrib, is deprecated. See here for more information.
Usage: (print-json x)
Prints x as JSON. Nil becomes JSON null. Keywords become
strings, without the leading colon. Maps become JSON objects, all
other collection types become JSON arrays. Java arrays become JSON
arrays. Unicode characters in strings are escaped as \uXXXX.
Numbers print as with pr.
Source