You are looking at historical revision 29171 of this page. It may differ significantly from its current revision.
A JSON reader and writer based on the Comparse parsing library. In contrast to the alternative implementations json and json-abnf its representation of JSON data types in Scheme can be fully customized. It's also possible to change how and what Scheme data types are serialized to JSON.
API[procedure] (read-json [port-or-string] #!key consume-trailing-whitespace)
Reads a JSON document from port-or-string which is (current-input-port) by default according to the current json-parsers.
By default trailing whitespace in the input is consumed (as per the grammar defined in RFC 4627). To disable this behavior (e.g. to allow early return when streaming a sequence of JSON documents) the keyword argument consume-trailing-whitespace can be passed as #f.[procedure] (write-json datum [port])
Writes the given JSON datum to port which is (current-output-port) by default according to the current (json-unparsers).[procedure] (json->string datum)
Returns a string containing the JSON representation of the given datum according to the current (json-unparsers).[parameter] (json-parsers [parsers])
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:
- pair (keys are represented as symbols)
- list of member pairs
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 #t. The datum is passed to the corresponding emitter function which is expected to write its JSON representation to (current-output-port). By default the following mappings apply:
- object (an alist with symbols for keys is expected)
- (lambda (x) (eq? x #t))
- (lambda (x) (eq? x #f))
- (lambda (x) (eq? x 'null))
About this egg
The source code is hosted at Bitbucket. Feel free to fork it and send pull requests there.
- Add consume-trailing-whitespace option
- Update to Comparse 0.0.2
- First release based on Comparse (previous versions were based on genturfa'i)
Copyright (C) 2011-2013 Moritz Heidkamp All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the <organization> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.