PageRenderTime 22ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/cl-json-patches.lisp

http://github.com/mtravers/wuwei
Lisp | 38 lines | 18 code | 8 blank | 12 comment | 0 complexity | c15ca2938ef3cc08636d1d133f7906dd MD5 | raw file
  1. (in-package :json)
  2. #|
  3. Extensions to cl-json/src/encoder.lisp
  4. New features, for encoding functions:
  5. :empty-list ==> "[]"
  6. :empty-dict ==> "{}"
  7. (:raw "function(foo) ...") ==>
  8. produces unquoted string for javascript
  9. TODO: make these work in the decoding direction
  10. |#
  11. (#+:ALLEGRO excl:without-redefinition-warnings #-:ALLEGRO progn
  12. ;;; changed to compatible with cl-json 0.4 -- will break in earlier versions
  13. (defmethod encode-json ((s (eql :empty-dict)) &optional (stream *json-output*))
  14. (write-string "{}" stream))
  15. (defmethod encode-json ((s (eql :empty-list)) &optional (stream *json-output*))
  16. (write-string "[]" stream))
  17. (defmethod encode-json ((s list) &optional (stream *json-output*))
  18. (cond ((eq (car s) :raw)
  19. (write-string (cadr s) stream))
  20. ((alistp s)
  21. (encode-json-alist s stream))
  22. (t (call-next-method s stream))))
  23. (defun alistp (l)
  24. (dolist (elt l t)
  25. (unless (and (consp elt)
  26. (typep (car elt) '(or symbol string)))
  27. (return-from alistp nil))))
  28. );excl:without-redefinition-warnings