diff --git a/guix-data-service/web/render.scm b/guix-data-service/web/render.scm index c4a8e85..02ec42d 100644 --- a/guix-data-service/web/render.scm +++ b/guix-data-service/web/render.scm @@ -39,6 +39,7 @@ render-static-asset render-html scm-alist->streaming-json + list->json-array render-json render-text not-found @@ -160,7 +161,7 @@ (lambda (port) (sxml->html sxml port))))))) -(define* (scm-alist->streaming-json alist port #:key unicode) +(define* (scm-alist->streaming-json alist port #:key (unicode #t)) (put-string port "{") (pair-for-each (lambda (pair) @@ -179,6 +180,16 @@ alist) (put-string port "}")) +(define* (list->json-array proc list port #:key (unicode #t)) + (put-string port "[") + (pair-for-each + (lambda (pair) + (scm->json (proc (car pair)) port #:unicode unicode) + (unless (null? (cdr pair)) + (put-string port ","))) + list) + (put-string port "]")) + (define* (render-json json #:key (extra-headers '()) (code 200) stream?)