JSON format and serializing ColdFusion query objects

Every so often there is a tiny problem that has you scratching your head until you RTFM. I love JSON, it’s totally awesome and the fact that you can not convert CF objects natively is even better! I ran into a small issue where I was using serializeJSON on a structure that contained a query object (don’t ask!). The problem was when the serialized string was deserialized using deserializeJSON the query was no longer a query, it was not a structure! It turns out that the serializeJSON function takes two parameters!

SerializeJSON(var[, serializeQueryByColumns])

The second optional parameter serializeQueryByColumns tells CF to handle queries in a special way. Now the trick is to remember to use the second parameter of the DeserializeJSON function which performs the reverse operation. The second parameter must be set to false for the query object to be recreated during deserialization.

Here are links to the serializeJSON and deserializeJSON in LiveDocs.

Share this post:
  • Print
  • email
  • Facebook
  • Twitter
  • Tumblr
  • del.icio.us
  • Digg
  • Reddit
  • Sphinn

Related Posts

This entry was posted in ColdFusion, Programming, Thinking and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.
blog comments powered by Disqus
  • Subscribe to my feed Subscriber via Email Follow Me on Twitter! Check me out on Facebook! Check me out on LinkedIn!