Discussion:
[Chicken-users] Returning JSON in Awful
David Ireland
2018-09-26 05:13:14 UTC
Permalink
Hi,

I've started using Awful 1.0 and having trouble returning a JSON string.
The inverted commas are being replaced by &quot. For example, using the
code below returns {"a" : 1 }

Should this be normal behavior when returning JSON strings?

Thanks.
David

(use
awful)

(enable-sxml
#t)



(define my-json "{\"a\" : 1
}")


(define (define-json path
body)

(define-page
path

(λ
()

(awful-response-headers '((content-type
"text/json")))

(body))

no-template:
#t))



(define-json
(main-page-path)

(λ ()
`(,my-json)))
Mario Domenech Goulart
2018-09-26 06:00:10 UTC
Permalink
Hi David,
I've started using Awful 1.0 and having trouble returning a JSON string. The inverted commas are being replaced by &quot. For example, using
the code below returns {"a" : 1 }
Should this be normal behavior when returning JSON strings?
Awful uses sxml-transforms behind the scenes to convert SXML to HTML,
and the sxml->html converter transforms `'' into `"'. You can
prevent that by using `(literal ,my-json) in your code. Example:

(define-json (main-page-path)
(λ ()
`(literal ,my-json)))

I see this is wrong in the documentation. I'm gonna fix it. Thanks for
reporting.

All the best.
Mario
(use awful)
(enable-sxml #t)
(define my-json "{\"a\" : 1 }")
(define (define-json path body)
(define-page path
(λ ()
(awful-response-headers '((content-type "text/json")))
(body))
no-template: #t))
(define-json (main-page-path)
(λ () `(,my-json)))
_______________________________________________
Chicken-users mailing list
https://lists.nongnu.org/mailman/listinfo/chicken-users
--
http://parenteses.org/mario
Loading...