json-utils

Provides some helpers for JSON data structures.

  1. json-utils
  2. Documentation
    1. Module json-utils
      1. Usage
      2. Argument Conventions
      3. json-undefined
      4. json-keyform
      5. json-undefined?
      6. json-keyform?
      7. json-array?
      8. json-object?
      9. json-collection?
      10. json-count
      11. json-ref
      12. json-fold
      13. json-map
      14. json-for-each
      15. json-foldl
  3. Examples
  4. Examples
  5. Requirements
  6. Author
  7. Repository
  8. Version history
  9. License

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) -> boolean

Is X the json-undefined value?

json-keyform?

[procedure] (json-keyform? X) -> boolean

Is X a valid KEYFORM value?

json-array?

[procedure] (json-array? X) -> boolean

Is X a vector?

json-object?

[procedure] (json-object? X) -> boolean

Is X a hash-table or an alist?

json-collection?

[procedure] (json-collection? X) -> boolean

Is X a json-array or json-object?

json-count

[procedure] (json-count JSON) -> fixnum

Returns 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

Examples

Requirements

srfi-1 srfi-69 vector-lib miscmacros moremacros

Author

Kon Lovett

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.