cl-json
cl-json copied to clipboard
encoder unicode bug
json:encode-json-to-string output ALL character as ASCII code. Non-ASCII become escape sequence. There's a post on stack overflow describing this: http://stackoverflow.com/questions/12304702/cl-json-encodes-unicode-chars-by-outputting-their-unicode-escape-string-in-ascii
After comment out some code, it works as I expected. However, I known't know whether those code are essential. Maybe doing this introduce another bug:
(defun write-json-chars (s stream)
"Write JSON representations (chars or escape sequences) of
characters in string S to STREAM."
(loop for ch across s
for code = (char-code ch)
with special
if (setq special (car (rassoc ch +json-lisp-escaped-chars+)))
do (write-char #\\ stream) (write-char special stream)
else;; if (< #x1f code #x7f)
do (write-char ch stream)
;; else
;; do (let ((special '#.(rassoc-if #'consp +json-lisp-escaped-chars+)))
;; (destructuring-bind (esc . (width . radix)) special
;; (format stream "\\~C~V,V,'0R" esc radix width code)))
))
AFAICT this is not actually a bug, judging from the Stack Overflow discussion. According to the RFC, pointed to by this Stack Overflow discussion http://stackoverflow.com/questions/4901133/json-and-escaping-characters, we are licensed to escape all the unicode characters.
I would prefer we keep this behavior for simplicity.