API for json.write
(1.1.x branch)
by
Stuart Sierra
Usage:
(ns your-namespace
(:require 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
Usage: (json-str x)
Converts x to a JSON-formatted string.
Source
print-json
multimethod
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