Monday, December 15, 2008

JSON in ColdFusion

Pretty excited these days about JSON... I've used it sporadically in many applications, but every month there appears to be new uses for it. I particularly enjoyed one use where we stored some interface preferences as a small JSON cookie. I also LOVE being able to call a CF webservice and auto-magically return JSON (covered in depth at Ben Nadel's blog here: JSON part II) - it's saved us a couple times.

Anyways, I saw a blog post today about the release of JSONUtil - very cool. It's a nice way to serialize and deserialize JSON in CF 7, and is based on CFJSON code.

In my main contract, we've been arguing a bit about returning JSON in the header vs. in the body. We are leaning heavily towards starting to return JSON in the response body, but we're a bit worried about the META tag that CF returns when working in development mode.

Here's some good reading about JSON and Prototype from Frank Tank. He argues nicely for putting JSON in the response body.

T

4 comments:

Unknown said...

JSON is awesome :) However, I could be wrong, but I don't think the META tag actually gets applied to the DEV version of ColdFusion. From what I can remember, the META tag only gets output when you try to use an expired or DEV version as a "production" version.

As such, I don't think that should weigh in on your choice of JSON locationing. Just my two cents.

I just pass it back as the body text and it's been working great for me.

Cats and Radishes Art said...

Good call Ben, thanks for the feedback. You're probably right - I don't see it in my current dev environment, but I've been bitten by it before. Glad to know I'm on the right track.

It's really nice to see all the JSON tools mature, both client side (Prototype, YUI, etc) and server side (CFJSON, JSONUtils, CF8 functionality).

Unknown said...

"META tag that CF returns"

Sorry, what kind of META tag are we talking about here?

Cats and Radishes Art said...

Hi Henry. We're talking about the 'Not for Production Use' tag when you're in development mode.

Steven Etat discusses it here:
http://www.talkingtree.com/blog/index.cfm?mode=entry&entry=80E120C1-50DA-0559-A0CE3D8628309982

I'm not sure what versions and conditions cause it, I just know I've been bitten before. That made me hesitate to consider returning JSON in the body of my responses.