src/json.lisp @ 6385b2a6b82a

Fix exit code
author Steve Losh <steve@stevelosh.com>
date Wed, 19 Dec 2018 10:16:08 -0500
parents 70497b31cb24
children (none)
(in-package :cacl)

(defun decode-json% (string)
  (let ((yason:*parse-json-booleans-as-symbols* t)
        (yason:*parse-json-arrays-as-vectors* t))
    (yason:parse string)))

(defun encode-json% (json &key indent)
  (with-output-to-string (s)
    (yason:encode json (if indent (yason:make-json-output-stream s) s))))


(define-command (decode-json dj) (string)
  (etypecase string
    (string (push! (decode-json% string)))))

(define-command (encode-json ej) (object)
  (etypecase object
    ((or hash-table vector null number (member yason:true yason:false) string)
     (push! (encode-json% object)))))