June 2007

CF8: Evolving JSON Support

When we first decided to include AJAX functionality in CF8, well, that was just about all that we had decided! Which was fun, because it gave me a broad mandate to go out and come up with some crazy ideas, and scary, because I didn’t have a clue what to do about it.

So we started small, and built native support for JSON into the server, with a fast Java JSON parser of our own, which provided the basis for the new JSON functions in CF8:

serializeJSON(<CFML object>, <serializeQueryByColumns>)

deserializeJSON(<JSON string>, <strictTypes>)

isJSON(<JSON string>)

I’m not going to get into the specifics of these functions here - Ben Nadel’s done a great job covering them on his blog. Also, a note, these function signatures are not final - we’re tweaking them a bit (just a bit, applications you write now will not be broken!) for the final release. But more on that later.

JSON has been gaining currency as an alternative to XML for data interchange for a variety of reasons: it’s lighter, easier to read and write, maps well to basic constructs in many languages (such as arrays and structs), and, perhaps most importantly for the dynamic web, plays well with yer average browser’s language of choice, JavaScript.

With just these basic functions, it becomes easy to consume JSON-powered web services, mash them up as you will, and spit them back out again. For instance, here’s a tasty morsel of a CFC I wrote to get data from del.icio.us JSON web services:

<cfcomponent output="false">

	<!---
	Gets del.icio.us tags for a user.
	The web service returns a JSON object, mapping tag names to
	numbers of posts with that tag, which deserializes to a CFML Struct.
	More details of the web service available at:
	http://del.icio.us/help/json/tags
	--->
	<cffunction name="getTags" access="remote" output="false">
		<cfargument name="userid">
		<cfset tagsURL = "http://del.icio.us/feeds/json/tags/#userid#?raw">
		<cfhttp url="#tagsURL#">
		<cfreturn deserializeJSON(cfhttp.fileContent)>
	</cffunction>

	<!---
	Gets posts for a user, optionally for a specified set of tags.
	The web service returns a JSON array of objects, one object per
	post. Each post object has the keys:
	u - URL
	d - description
	t - tags
	This deserializes to a CFML Array of Structs, with one Struct per post.
	More details of the web service available at:
	http://del.icio.us/help/json/posts
	--->
	<cffunction name="getPosts" access="remote" output="false">
		<cfargument name="userid">
		<cfargument name="tags">
		<cfset var tagList = replace(tags, ",", "+")>
		<cfset tagsURL = "http://del.icio.us/feeds/json/#userid#/#tagList#?raw&count=30">
		<cfhttp url="#tagsURL#">
		<cfreturn deserializeJSON(cfhttp.fileContent)>
	</cffunction>

</cfcomponent>

CFHTTP to the service URL, deserializeJSON on the response, and, all of a sudden, you have native CFML types to extract data from. Doesn’t get much easier than that! I’ll show off an AJAX application that I wrote with this CFC in a little while.

Given CF’s ability to consume data from a variety of sources (databases, LDAP servers, FTP, MS Exchange, HTTP, etc.), along with native support for common data formats (XML, and now JSON), and the large variety of web services out there, you’re now limited only by your own imagination in the mashup applications you can build. Go forth and multiply!

coldfusion
code
technology

Comments (1)

Permalink

New Beginnings

So it’s that time of year again - all the cool kids are out at CFUnited. I would have loved to have been there, but it is not to be.

Why? Well, with much reluctance, I am leaving Adobe, for entirely personal reasons. If I could, I would have stayed on here for many years to come, and seen ColdFusion through many more releases. The team is, without a doubt, the finest I’ve ever worked with, it’s been quite an experience putting ColdFusion 8 out, working on everything from language design to server scalability, and it has been a pleasure getting to know all the great folks in the ColdFusion community, with whom I will continue to be involved. As Damon likes to say, you can join the ColdFusion team, but you can never leave… Sinister and megalomaniacal, that’s our Damon! ;-)

Anasuya and I will be moving to California, where she’ll get down to the arduous task of writing her D.Phil. thesis, and I’ll enroll in the Master’s at the UC Berkeley School of Information, a.k.a. the iSchool. In recent years, I’ve found myself fascinated by the impact that the technologies we build have upon society. The iSchool’s faculty and roster of courses, which meld computer science and the social sciences, should help shape these interests, and give me space to think about what I want to do next. I’m really excited to be studying at the iSchool - this will be a whole new set of challenges and possibilities.

It’s been a lovely 7 years in Bangalore - I met Anasuya and got married here, studied classical guitar at the Bangalore School of Music, jammed in various bands with weird names, circumnavigated the city on a bicycle, did the Koshy’s Sunday brunch (many times), drank too much beer at Peco’s, and so much more. Sadly, I’ve also watched the city decline in this time. Just as the software and services boom drew engineers to Bangalore, so it also drew land sharks, and their ilk. Couple that with an unstable political environment, and you have a recipe for disaster. I can only hope that the citizen’s groups working to better the city will find success in their efforts.

This blog will continue to be, of course, and while I’ll still be writing about technology, I’ll also be talking about the social impact of computing (intelligently, I hope!). And there will be lots more CF8 in the days to come - I’ve been rather insanely busy helping mop things up for the final release build, but I should have more time free to blog CF8 features from now onwards, especially the AJAX stuff, of which I am particularly proud.

coldfusion

Comments (15)

Permalink

New ColdFusion blogs

A couple of new ColdFusion team blogs for you to watch - as though there isn’t enough Scorpio buzz out there already!

Rakshith, a great guy who worked with me on the AJAX stuff, has got his blog up - he’ll be writing up new Scorpio features that he worked on, as will I, in the days to come.

Ahmad Patan, a member of our QA team, has started the CFPDF blog, to talk about new PDF manipulation and PDF form processing features in Scorpio. The QA guys pair up with development team members right from design time, so they end up knowing the features inside out, upside down, sideways, backward, and any other way you’d like to write your CFML code.

coldfusion
technology

Comments (2)

Permalink