[cl-json-devel] Characters

Ken Harris kengruven at gmail.com
Fri Dec 29 01:00:20 UTC 2006


Hello!

One thing I discovered when I tried to encode a big s-exp with
encode-json-to-string is that it doesn't support characters.

This kind of makes sense, since JSON itself doesn't have a separate
"character" type, and some of the big usrs of JSON (ECMAscript and
Python) don't, either.  A JSON decoder couldn't tell what's a length-1
string, and what's a character.

OTOH, for my program, it would be really handy to *encode* characters directly.

I decided to try writing a patch, after about 5 seconds came up with this:

(defmethod encode-json ((c character) stream)
  (encode-json (string c) stream))

Since this is Lisp, it's both insanely easy, and it doesn't have to be
part of cl-json for me to use it as if it was.  :-)

I guess it doesn't really benefit me for this to be part of cl-json,
but if that's of any use to you, feel free to use/add it.


cheers,


- Ken



More information about the cl-json-devel mailing list