From 62cf3ff7cbd8bed740e8ac7fbf64db4aa32e42f3 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Fri, 4 Jul 2025 10:29:59 +0100 Subject: [PATCH] Add list->json-array --- guix-data-service/web/render.scm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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?)