On Thu, Apr 7, 2011 at 4:07 PM, Jim Barrows <jim.barrows@gmail.com> wrote:
I'm trying to encode a list of plists, and encode-json-plist-to-string doesn't appear to do it.

Yes, because the first list is a list and not a plist.
 
My newbiness is not seeing a better answer then to loop through the list, and encode each plist separately, concatentate the strings together to form the array.

If you go that route, I would rather wrap a string-stream with with-output-to-string and encode each individual plist to this stream (not the -to-string functions) to avoid string concatenation at the end.

 
 That doesn't seem too lispy to me.
Is there a better way?
 
I suggest using the explicit encoder for more control, but then you would need to change your p-lists slightly.
I assume you want the plists to be json objects, and the list to be a json array.

Both these examples give the same result:

[{"a":"c","d":"c"},{"foo":true,"bar":false}

;; More json-javascriptish terminolgy
(princ
   (json:with-explicit-encoder
      (json:encode-json-to-string
         '(:array (:object :a "c" :d "c")
                     (:object :foo t :bar (:false))))))

;; More lispish terminology
(princ
   (json:with-explicit-encoder
      (json:encode-json-to-string
         '(:list (:plist :a "c" :d "c")
                 (:plist :foo t :bar (:false))))))

Or you could use the streaming encoder.

/Henrik Hjelte