summaryrefslogtreecommitdiff
path: root/lib/zambyte/meta/sagittarius.scm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/zambyte/meta/sagittarius.scm')
-rw-r--r--lib/zambyte/meta/sagittarius.scm35
1 files changed, 22 insertions, 13 deletions
diff --git a/lib/zambyte/meta/sagittarius.scm b/lib/zambyte/meta/sagittarius.scm
index 3b5a741..97deb0b 100644
--- a/lib/zambyte/meta/sagittarius.scm
+++ b/lib/zambyte/meta/sagittarius.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)
(if (eq? (*json-map-type*) 'vector)
(apply vector pairs)
@@ -38,13 +27,33 @@
(define (json-null? obj)
(eq? obj json-null))
+ (define (json-object-contains-key? obj key)
+ (and (assoc key (json-object->alist 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 key (json-object->alist json))))
- (cdr pair)))
+ (or (and-let* ((pair (assoc key (json-object->alist json))))
+ (cdr pair))
+ ((json-key-not-found))))
(define (json-list-ref json index)
(list-ref (json-list->list json) index))
+ (define (json-list-length json)
+ (if (eq? (*json-map-type*) 'vector)
+ (length json)
+ (vector-length json)))
+
(define (json-object->alist json)
(if (eq? (*json-map-type*) 'vector)
(vector->list json)