json-utils
Provides some helpers for JSON data structures.
TOC »
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
- json-undefined #!optional UNDEFparameter
json-keyform
- json-keyform #!optional KEYFORMparameter
- KEYFORM
- default 'symbol
json-undefined?
- json-undefined? Xprocedure
Is X the json-undefined value?
json-keyform?
- json-keyform? Xprocedure
Is X a valid KEYFORM value?
json-array?
- json-array? Xprocedure
Is X a vector?
json-object?
- json-object? Xprocedure
Is X a hash-table or an alist?
json-collection?
- json-collection? Xprocedure
Is X a json-array or json-object?
json-count
- json-count JSONprocedure
Returns the number of elements in the JSON.
json-ref
- json-ref JSON KEY ...procedure
Returns the value in the JSON at the reference path KEY ....
json-fold
- json-fold JSON FUNCprocedure
- FUNC
- (KEY VAL ACC -> *)
json-map
- json-map JSON FUNCprocedure
- FUNC
- (KEY VAL ACC -> *)
json-for-each
- json-for-each JSON PROCprocedure
- PROC
- (KEY VAL -> void)
json-foldl
- json-foldl JSON FUNC *procedure
- 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.