json is a Igropyr's official JSON library.
install: raven install json
use: (import (json json))
string->json
(string->json string)
"{key1: value1, key2: value2, key3: value3 ...}" => ((key1 . value2)(key2 . value2)(key3 . value3) ...)
"[value1, value2, value3 ...]" => #(value1 value2 value3 ...)
json->string
(json->string json)
((key1 . value2)(key2 . value2)(key3 . value3) ...) => "{key1: value1, key2: value2, key3: value3 ...}"
#(value1 value2 value3 ...) => "[value1, value2, value3 ...]"
vector->array
(vector->array vector)
#(value1 value2 value3 ...) => ((0 . value1)(1 . value2)(2 . value3) ...)
array->vector
(vector->array list)
((0 . value1)(1 . value2)(2 . value3) ...) => #(value1 value2 value3 ...)
json-ref
(json-ref json key)
(json-ref json key1 key2 key3 ...)
use to return the value of a key in specified location of JSON.
when value is: json-ref return:
true => #t
false => #f
null => '()
when it accept plural keys:
(json-ref json key1 key2 key3) =
(json-ref (json-ref (json-ref json key1) key2) key3)))
following procedures are embedded high-order function map
- They can filter multiple layer and operate multiple branches at the same time.
- "Verify" may be a key, a boolean #t or a procedure.
- When it's a key, it specife the branch to throw this layer.
- When it's a #t, it means operate all of branch of this layer.
- When it's a procedure, it match all of keys with in this layer.
- The procedure will receive the key of branch and have to return boolean.
- When it accept plural verifys, each key will match each layer.
json-set
(json-set json verify value)
(json-set json verify1 verify2 verify3 ... value)
use to modify a value or values in specified location of JSON.
"value" may be a value or a procedure.
when it's a value, it will directly replace the old one's.
when it's a procedure, it must accept one argument (current value of key) and return a new value to replace.
Do NOT set #t, #f and '() to values, use 'true, 'false and 'null.
json-push
(json-push json key value)
(json-push json verify1 verify2 verify3 ... key value)
use to add a key-value pair to json.
it has to have a key value pair in arguments.
json-drop
(json-drop json verify)
(json-drop json verify1 verify2 verify3 ...)
use to delete a key-value pair from list.
the lastest verify only accept a key or a procedure.
json-reduce
(json-set json verify procedure)
(json-set json verify1 verify2 verify3 ... procedure)
it likes json-set, the diffrent is it accept only procedure for the lastest argument.
the procedure will receive two arguments: list of key of all layers `'(key1 key2 key3 ...)` and the current value.
it have to return a new value what you want to put.
be attention that, the list of keys is not the list of verifys. that's means if you use #t to pass all branch of a layer or macth a check procedure to filter them, the procedure will receive its key whitch use to pass this layer not the keys of all match path in this layer.