Next: , Up: MIME   [Contents]

13.1 JSON

GNU Artanis integrated the third-party module guile-json. You may use #:mime method to handle JSON:

(get "/json" #:mime 'json
  (lambda (rc)
    (let ((j (json (object ("name" "nala") ("age" 15)))))
      (:mime rc j))))

For example:

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

scm->json will print the result directly.

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