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.scm56
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/zambyte/meta/sagittarius.scm b/lib/zambyte/meta/sagittarius.scm
new file mode 100644
index 0000000..3b5a741
--- /dev/null
+++ b/lib/zambyte/meta/sagittarius.scm
@@ -0,0 +1,56 @@
+(import (text json)
+ (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)
+ (apply list pairs)))
+
+ (define (json-list . objs)
+ (if (eq? (*json-map-type*) 'vector)
+ (apply list objs)
+ (apply vector objs)))
+
+ (define json-null 'null)
+
+ (define (json-object? json)
+ (if (eq? (*json-map-type*) 'vector)
+ (vector? json)
+ (list? json)))
+
+ (define (json-list? json)
+ (if (eq? (*json-map-type*) 'vector)
+ (list? json)
+ (vector? json)))
+
+ (define (json-null? obj)
+ (eq? obj json-null))
+
+ (define (json-object-ref json key)
+ (and-let* ((pair (assoc key (json-object->alist json))))
+ (cdr pair)))
+
+ (define (json-list-ref json index)
+ (list-ref (json-list->list json) index))
+
+ (define (json-object->alist json)
+ (if (eq? (*json-map-type*) 'vector)
+ (vector->list json)
+ json))
+
+ (define (json-list->list json)
+ (if (eq? (*json-map-type*) 'vector)
+ json
+ (vector->list json))))