Next: , Up: MIME [Contents]

17.1 JSON

GNU Artanis integrates the third-party module guile-json to parse json. You can use the #:mime method to handle JSON:

(get "/json" #:mime 'json
 (lambda (rc)
 (let ((j (scm->json-string '(("name" . "nala") ("age" . 15)))))
 (:mime rc j))))

For example:

(define my-json
 '((name . nala) (age . 15)
 (read_list
 ("book1" "The interpreter and structure of Artanis")
 ("book2" "The art of Artanis programming"))))
(scm->json-string my-json) ; scm->json will print a json string
;; ==> {"name" : "nala",
;; "age" : 15,
;; "read_list" : {"book2" : "The art of Artanis programming",
;; "book1" : "The interpreter and structure of Artanis"}}

scm->json will return a hash-table to represent a JSON object.

If you need to format JSON as a string to return to the client, please use scm->json-string.

AltStyle によって変換されたページ (->オリジナル) /