JSON

Richard Gaskin ambassador at fourthworld.com
Tue Jun 4 10:32:16 EDT 2013


Mark Wieder wrote:
> Well, what you want to push to the server depends on the key:value
> pairs they expect. Here's a simple example:
>
> {"name" : "Tom McGrath", "favorite_author" : "Dr. Seuss"}
>
> Here's an example from a mongodb student database:
>
> {"_id": {"oid" : 1234},
>   "student_id" : 0,
>   "class_id" : 49,
>   "scores" : [
>     {"type" : "exam", "score" : 54.6}
>     {"type" : "quiz", "score" : 65.6}
>     {"type" : "homework", "score" : 78}
>     {"type" : "homework", "score" : 80.4}
>   ]
> }

JSON is a good argument for what I like to call LSON, where the "L" 
stands for "LiveCode" of course. :)

Similar to MongoDB's BSON, LSON is a very convenient way to move 
hierarchically-ordered data back and forth between sever and client, 
compressing arrays and then Base64'ing them for efficient, robust 
network transport:

function ArrayToLSON pArray
     put arrayEncode(pArray) into tData
     put compress(tData) into tData
     return base64Encode(tData)
end ArrayToLSON

function LSONToArray pData
   try
     put base64Decode(pData) into tData
     put decompress(tData) into tData
     put arrayDecode(tData) into tArray
   catch tErr
     throw "Error unpacking LSON data"
   end try
   return tArray
end LSONToArray

My understanding is that LC's RevOnline uses that format, and I believe 
Andre is fond of it too.

Of course this only works if you have LC on both ends of the 
client-server setup, but who doesn't? :)

--
  Richard Gaskin
  Fourth World
  LiveCode training and consulting: http://www.fourthworld.com
  Webzine for LiveCode developers: http://www.LiveCodeJournal.com
  Follow me on Twitter:  http://twitter.com/FourthWorldSys




More information about the use-livecode mailing list