Namespace: joker.json
v1.0Contents
Summary
Encodes Joker values to JSON and decodes JSON strings or streams into Joker values.
Index
Constants
Constants are variables with :const true in their metadata. Joker currently does not recognize them as special; as such, it allows redefining them or their values.-
(None.)
Variables
-
(None.)
Functions, Macros, and Special Forms
-
json-seq
Function v1.0(json-seq rdr)(json-seq rdr opts)Returns successive JSON values from rdr as a lazy sequence.
rdr must be a string or implement io.Reader. Multiple top-level JSON values
may be read from one stream. Decoding happens as the sequence is realized, so
malformed later input may throw Error only when that element is requested.
opts may contain:
- keywords? - truthy to convert JSON object keys from strings to keywords -
read-string
Function v1.0(read-string s)(read-string s opts)Parses one JSON value from s and returns the corresponding Joker value.
JSON objects become maps, arrays become vectors, strings become strings,
booleans become booleans, null becomes nil, and JSON numbers become Int when
integral or Double otherwise. Throws Error when s is not valid JSON.
opts may contain:
- keywords? - truthy to convert JSON object keys from strings to keywords
Example:
(joker.json/read-string "{\"name\":\"Ada\"}" {:keywords? true})
;; => {:name "Ada"} -
write-string
Function v1.0(write-string v)(write-string v opts)Returns the JSON encoding of v.
Keywords are encoded without their leading colon. Map keys are converted to
strings, Seqable values become arrays, and numeric values are encoded through
their double representation.
opts may contain:
- prefix (string)
- indent (string)
When either is non-empty, pretty-printing follows Go json.MarshalIndent
semantics. Throws Error when JSON encoding fails.
Example:
(joker.json/write-string {:name "Ada" :scores [1 2]})
;; => "{\"name\":\"Ada\",\"scores\":[1,2]}"