write
function
clojure.data.json/write
(write [x writer & {:as 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 \/
:sql-date-converter function
Single-argument function used to convert a java.sql.Date to
a java.time.Instant. As java.sql.Date does not have a
time-component (which is required by java.time.Instant), it needs
to be computed. The default implementation, `default-sql-date->instant-fn`
uses
```
(.toInstant (.atStartOfDay (.toLocalDate sql-date) (java.time.ZoneId/systemDefault)))
```
:date-formatter
A java.time.DateTimeFormatter instance, defaults to DateTimeFormatter/ISO_INSTANT
: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.
:default-write-fn function
Function to handle types which are unknown to data.json. Defaults
to a function which throws an exception. Expects to be called with
three args, the value to be serialized, the output stream, and the
options map.
:indent boolean
If true, indent json while writing (default = false).
Examples
No examples yet. Be the first to add one!