(define-library (zambyte meta json) ;; portable (export json-ref json-value?) ;; non-portable (export string->json json->string json-object json-list json-null json-object? json-list? json-null? json-object-ref json-list-ref json-object->alist json-list->list) (import (scheme base)) ;; portable (begin (define (json-ref json key . keys) (let ((ref (cond ((json-object? json) json-object-ref) ((json-list? json) json-list-ref) (else (error "json-ref: cannot get reference on json value" json))))) (if (null? keys) (ref json key) (apply json-ref (ref json key) keys)))) (define (json-value? obj) (or (boolean? obj) (number? obj) (string? obj) (json-null? obj) (json-list? obj) (json-object? obj)))) ;; non-portable (cond-expand ((and (library (macduffie json)) (srfi 69)) (include-library-declarations "macduffie.scm")) ((and guile (library (json))) (include-library-declarations "guile.scm")) (gauche (include-library-declarations "gauche.scm")) (gerbil (include-library-declarations "gerbil.scm")) (sagittarius (include-library-declarations "sagittarius.scm")) ((library (chibi json)) (include-library-declarations "chibi.scm")) ((library (srfi 180)) (include-library-declarations "180.scm")) (else (error "No implementation of JSON library available."))))