diff options
author | Robby Zambito <contact@robbyzambito.me> | 2023-02-12 22:46:48 -0500 |
---|---|---|
committer | Robby Zambito <contact@robbyzambito.me> | 2023-02-12 22:46:48 -0500 |
commit | b1294088059fe22d1a05d0f9637fdd598795d8ea (patch) | |
tree | 2031c4c455d3e26c4ab985eae678de7abc1a0042 /lib/zambyte/meta/180.scm | |
parent | 91adcf023b0c2684991161661032e1aae3cd6b0c (diff) |
Add json-object-contains-key?, json-list-length, and json-key-not-found.
Update README accordingly and with add examples.
Diffstat (limited to 'lib/zambyte/meta/180.scm')
-rw-r--r-- | lib/zambyte/meta/180.scm | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/lib/zambyte/meta/180.scm b/lib/zambyte/meta/180.scm index 735a895..71ee1a8 100644 --- a/lib/zambyte/meta/180.scm +++ b/lib/zambyte/meta/180.scm @@ -2,17 +2,6 @@ (srfi 1) (srfi 2)) (begin - (define (string->json str) - (call-with-port (open-input-string str) - (lambda (port) - (json-read port)))) - - (define (json->string json) - (call-with-port (open-output-string) - (lambda (port) - (json-write json port) - (get-output-string port)))) - (define (json-object . pairs) (map (lambda (pair) @@ -25,11 +14,27 @@ (define json-list? vector?) ;; json-null? already defined in srfi 180 + (define (json-object-contains-key? obj key) + (and (assoc (string->symbol key) obj) #t)) + + (define (string->json str) + (call-with-port (open-input-string str) + (lambda (port) + (json-read port)))) + + (define (json->string json) + (call-with-port (open-output-string) + (lambda (port) + (json-write json port) + (get-output-string port)))) + (define (json-object-ref json key) - (and-let* ((pair (assoc (string->symbol key) json))) - (cdr pair))) + (or (and-let* ((pair (assoc (string->symbol key) json))) + (cdr pair)) + ((json-key-not-found)))) (define json-list-ref vector-ref) + (define json-list-length vector-length) (define (json-object->alist json) (map |