(write x writer & options)
Write JSON-formatted output to a java.io.Writer. Options are
key-value pairs, valid options are:
:escape-unicode boolean
If true (default) non-ASCII characters are escaped as \uXXXX
:escape-js-separators boolean
If true (default) the Unicode characters U+2028 and U+2029 will
be escaped as \u2028 and \u2029 even if :escape-unicode is
false. (These two characters are valid in pure JSON but are not
valid in JavaScript strings.)
:escape-slash boolean
If true (default) the slash / is escaped as \/
:key-fn function
Single-argument function called on map keys; return value will
replace the property names in the output. Must return a
string. Default calls clojure.core/name on symbols and
keywords and clojure.core/str on everything else.
:value-fn function
Function to transform values in maps before writing. For each
key-value pair in an input map, called with two arguments: the
key (BEFORE transformation by key-fn) and the value. The
return value of value-fn will replace the value in the output.
If the return value is a number, boolean, string, or nil it
will be included literally in the output. If the return value
is a non-map collection, it will be processed recursively. If
the return value is a map, it will be processed recursively,
calling value-fn again on its key-value pairs. If value-fn
returns itself, the key-value pair will be omitted from the
output. This option does not apply to non-map collections.
Source
(defn write
"Write JSON-formatted output to a java.io.Writer. Options are
key-value pairs, valid options are:
:escape-unicode boolean
If true (default) non-ASCII characters are escaped as \\uXXXX
:escape-js-separators boolean
If true (default) the Unicode characters U+2028 and U+2029 will
be escaped as \\u2028 and \\u2029 even if :escape-unicode is
false. (These two characters are valid in pure JSON but are not
valid in JavaScript strings.)
:escape-slash boolean
If true (default) the slash / is escaped as \\/
:key-fn function
Single-argument function called on map keys; return value will
replace the property names in the output. Must return a
string. Default calls clojure.core/name on symbols and
keywords and clojure.core/str on everything else.
:value-fn function
Function to transform values in maps before writing. For each
key-value pair in an input map, called with two arguments: the
key (BEFORE transformation by key-fn) and the value. The
return value of value-fn will replace the value in the output.
If the return value is a number, boolean, string, or nil it
will be included literally in the output. If the return value
is a non-map collection, it will be processed recursively. If
the return value is a map, it will be processed recursively,
calling value-fn again on its key-value pairs. If value-fn
returns itself, the key-value pair will be omitted from the
output. This option does not apply to non-map collections."
[x ^Writer writer & options]
(let [{:keys [escape-unicode escape-js-separators escape-slash key-fn value-fn]
:or {escape-unicode true
escape-js-separators true
escape-slash true
key-fn default-write-key-fn
value-fn default-value-fn}} options]
(binding [*escape-unicode* escape-unicode
*escape-js-separators* escape-js-separators
*escape-slash* escape-slash
*key-fn* key-fn
*value-fn* value-fn]
(-write x (PrintWriter. writer)))))