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-static-asset
render-html render-html
scm-alist->streaming-json scm-alist->streaming-json
list->json-array
render-json render-json
render-text render-text
not-found not-found
@ -160,7 +161,7 @@
(lambda (port) (lambda (port)
(sxml->html sxml 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 "{") (put-string port "{")
(pair-for-each (pair-for-each
(lambda (pair) (lambda (pair)
@ -179,6 +180,16 @@
alist) alist)
(put-string port "}")) (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 '()) (define* (render-json json #:key (extra-headers '())
(code 200) (code 200)
stream?) stream?)