(index ("read-json" 0) ("write-json" 654) ("json->string" 1167) ("json-parsers" 1316) ("json-unparsers" 1831))
(def (sig (procedure "(read-json [port-or-string] #!key consume-trailing-whitespace)" (id read-json))) (p "Reads a JSON document from " (tt "port-or-string") " which is " (tt "(current-input-port)") " by default. The returned object is assembled according to the current " (tt "json-parsers") " parameter.") (p "By default trailing whitespace in the input is consumed (as per the grammar defined in " (link "http://www.ietf.org/rfc/rfc4627.txt" "RFC 4627") "). To disable this behavior (e.g. to allow early return when streaming a sequence of JSON documents) the keyword argument " (tt "consume-trailing-whitespace") " can be passed as " (tt "#f") "."))
(def (sig (procedure "(write-json datum [port])" (id write-json))) (p "Writes the given JSON " (tt "datum") " to " (tt "port") " which is " (tt "(current-output-port)") " by default. " (tt "datum") "'s conversion to JSON is inferred by its Scheme type via the current " (tt "json-unparsers") " parameter.") (p "A common gotcha is that the default " (tt "json-unparsers") " assume lists to be alists which are written as JSON objects. If you want to write a JSON array you need to pass a Scheme vector instead."))
(def (sig (procedure "(json->string datum)" (id json->string))) (p "Like " (tt "write-json") " but returns a string instead of writing to a port."))
(def (sig (parameter "(json-parsers [parsers])" (id json-parsers))) (p "An alist which maps JSON data type symbols to procedures which are used to convert the corresponding data types to Scheme data structures. By default the following mappings apply:") (dl (dt "string") (dd "string") (dt "number") (dd "number") (dt "member") (dd "pair (keys are represented as symbols)") (dt "object") (dd "list of member pairs") (dt "array") (dd "vector") (dt "true") (dd "#t") (dt "false") (dd "#f") (dt "null") (dd "'null")))
(def (sig (parameter "(json-unparsers [unparsers])" (id json-unparsers))) (p "An alist which maps predicate functions to emitter functions. When a datum is to be written the predicates are tried in order until one returns " (tt "#t") ". The datum is passed to the corresponding emitter function which is expected to write its JSON representation to " (tt "(current-output-port") "). By default the following mappings apply:") (dl (dt "list?") (dd "object (an alist with symbols for keys is expected)") (dt "vector?") (dd "array") (dt "string?") (dd "string") (dt "number?") (dd "number") (dt "(lambda (x) (eq? x #t))") (dd "\"true\"") (dt "(lambda (x) (eq? x #f))") (dd "\"false\"") (dt "(lambda (x) (eq? x 'null))") (dd "\"null\"")))
