Add list->json-array

This commit is contained in:
Christopher Baines 2025-07-04 10:29:59 +01:00
parent df79bc198e
commit 62cf3ff7cb

View file

@ -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?)