json-utils
Provides some helpers for JSON data structures.
Documentation
Utilities for accessing data structures loaded or generated by, other, JSON libraries, such as medea. Where a JSON Array is a vector and an Object is a hash-table or alist. Note that a vector does not preserve the sparse nature of a JSON Array.
This library is not agnostic to the JSON representation. The json egg, for example, preserves the sparse nature of the JSON Array by using a list. And an Object is represented by a (vector-of (pair symbol *)).
Module json-utils
Usage
(import json-utils)
Argument Conventions
- JSON
- (or vector hash-table alist) ; JSON collection
- KEY
- (or fixnum string symbol) ; JSON key
- KEYFORM
- 'symbol or 'string
The acceptable JSON key for an Object depends on (json-keyform) and the index for an Array must resolve (symbol->string->real->floor->exact) to a fixnum.
json-undefined
[parameter] (json-undefined [UNDEF]) -> *json-keyform
[parameter] (json-keyform [KEYFORM]) -> symbol- KEYFORM
- default 'symbol
json-undefined?
[procedure] (json-undefined? X) -> booleanIs X the json-undefined value?
json-keyform?
[procedure] (json-keyform? X) -> booleanIs X a valid KEYFORM value?
json-array?
[procedure] (json-array? X) -> booleanIs X a vector?
json-object?
[procedure] (json-object? X) -> booleanIs X a hash-table or an alist?
json-collection?
[procedure] (json-collection? X) -> booleanIs X a json-array or json-object?
json-count
[procedure] (json-count JSON) -> fixnumReturns the number of elements in the JSON.
json-ref
[procedure] (json-ref JSON KEY ...) -> *Returns the value in the JSON at the reference path KEY ....
json-fold
[procedure] (json-fold JSON FUNC) -> *- FUNC
- (KEY VAL ACC -> *)
json-map
[procedure] (json-map JSON FUNC) -> list- FUNC
- (KEY VAL ACC -> *)
json-for-each
[procedure] (json-for-each JSON PROC)- PROC
- (KEY VAL -> void)
json-foldl
[procedure] (json-foldl JSON FUNC *) -> *- FUNC
- (ACC KEY VAL -> *)
Examples
- For now please see the "tests" directory in the egg source.
Examples
- For now the use of a vector does not preserve the sparse nature of a JSON Array. A JSON reader/writer that used the sparse-vectors egg would be useful.
Requirements
srfi-1 srfi-69 vector-lib miscmacros moremacros
Author
Repository
This egg is hosted on the CHICKEN Subversion repository:
https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/json-utils
If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.
Version history
- 1.1.0
- Add json-keyform?
- 1.0.0
- Hello
License
Copyright (C) 2022 Kon Lovett. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.