SerializeJson Sucks II

I want to thank those of you who read my rant and added your opinions, questions and corrections (Thanks Nic loosely typed of course :) )

Letting of steam certainly helps and getting feedback helps focus too.

Thanks Kai, I will attempt to clarify my problem with SerializeJSON.

Russ S. I will definitely look at those projects as serializejson for my project is not usable.


Structkeyexists or Yes, No, Maybe So

Perhaps I'm just being picky here but why do some functions in CF return a boolean (true/false) and others return a boolean (yes/no)?

For example StruckKeyExists() is one such culprit it returns a Yes or a No, which in CF is boolean. The problem naturally comes in if you decide to send the results from a StructKeyExits to a language that doesn't understand that yes/no in reality means true/false. Even if you use the serializeJSON() function to convert your data to a JSON formatted string, the Yes/NO does not convert to a boolean in JavaScript whereas a True/False is. In fact serializeJSON converts Yes/No to a string!

The CF9 documentation for StructKeyExists even indicates that the result of the function is True if the key exists. They say nothing about Yes.


Converting structkeys to lowercase

As you most probably know when you create a structure and don't quote the keys they are automatically converted to uppercase.

<cfset myStruct = structNew()>
<cfset mystruct.two=2>
<cfset mystruct.three=3>

When you dump it out you get:

and when you serialize it to json all the keys are also uppercase. This can be problematic since JS is case sensitive. You could create your structure with lowercase keys then serializeJSON() will maintain the case of your structure, but if you don't have control of the structure itself you need to do something to to convert only the structure keys to lowercase.

As a quick and dirty way of doing this I build a recursive function to do just that. Firstly I ran the structure through SerializeJSON() just in case the structure contained other datatypes that also need to be serialized, I think deserialized the string back into a structure. Make sure you use strict mapping so that the function doesn't try to convert your query back into a query. Then call the recursive function to go through and change all the keys to lowercase.

Here is the function:

    <cffunction name="convertStructToLower" access="public" returntype="struct">
        <cfargument name="st" required="true" type="struct">

        <cfset var aKeys = structKeyArray(st)>
        <cfset var stN = structNew()>
        <cfset var i= 0>
        <cfset var ai= 0>
        <cfloop array="#aKeys#" index="i">
            <cfif isStruct(st[i])>
                <cfset stN['#lCase(i)#'] = convertStructToLower(st[i])>
            <cfelseif isArray(st[i])>
                <cfloop from=1 to="#arraylen(st[i])#" index="ai">
                    <cfif isStruct(st[i][ai])>
                        <cfset st[i][ai] = convertStructToLower(st[i][ai])>
                        <cfset st[i][ai] = st[i][ai]>
                <cfset stN['#lcase(i)#'] = st[i]>
                <cfset stN['#lcase(i)#'] = st[i]>
        <cfreturn stn>

As you can see it also handles the case where you have an array of structures inside a structure.

I've tested it with nested structures that contain arrays of structures and it seems to work just fine. Perhaps you will find it useful for any Ajax stuff you are doing.

Happy Coding...

The Importance of Variable Prefixing

I remember my first official University programming course. We were to learn the language Pascal. Pascal is a socalled "teaching" programming language primarily to teach structured programming.


Mango Blog Test Drive

Last night I downloaded Mango Blog and did a local install to take it for a test drive. I've been using BlogCFC since I started this blog and it has served me well so far, but the Mango Blog interface is just so much better.


A New Chapter

Friday is my last day with my current employer, who happens to also be my first employer in Germany.


Extending Built-in Functions in Railo

I'm not sure how I missed this blog entry by Todd Raferty on the Railo Blog, but this is definitely worth mentioning again.


Coldfusion and jQuery

It's been relatively quiet in Munich on the CF front (user group meetings) but a nudge in the right direction always helps to get things moving. The Munich CFUG will be getting together on May 5th


Railo is Open-Source So Now What?

Unless you have been living under a rock you will have read that the alternative CFML engine Railo has released their much anticipated version 3.1 as open-source under jBoss.


Railo 3.1 Now Available!

After the announcement at last years Scotch on the Rocks that Railo would be going open source, and be included as a project, the day has finally arrived.

Railo Goes Open-Source


Railo Hosting with Alurium

Want to try out Railo but having trouble finding a hosting company? Well Alurium just started offering Railo hosting plans (Along with PHP and Ruby). It's a brand new start-up started by Peter Amiri.


Coldfusion 9 CFScript enhancement

I'm not exactly sure how I missed Ray Camdens post on the proposed CFScript enhancements for ColdFusion 9 but it's never too late to throw in my own two cents. I think it's awesome!


Ask Gary: Advanced Charting

I got an email from a reader yesterday asking about CFCHART and my JFREE custom tags:

Hi - i noticed your blog entry from earlier this year about work you were doing on a CF custom tag interface to JFREE, and was wondering how that work was coming along. I'm looking at try to do charting beyond what CFCHART is capable of, and this looked like a nice alternative. thanks!


Interesting Coldfusion Behavior

I wanted to test a PHP remote script today using CFHTTP method=GET. The remote script requires a few variables to be passed to it and well I wanted to initialize them using the cfparam tag.


Coldfusion Camp tickets in short supply!

I recently received word that there aren't many tickets left for the Coldfusion Camp in Munich. If you were thinking of attending then now would be a good idea to register before it sells out!

See you there!

Installing Railo 3 on Linux (CentOS): Part 2

In my previous post we started installing Railo on the CentOS Linux distribution. As most of us know installing applications on a Linux system sometimes requires more than one step. This installation is just that type.


Little Railo Gotcha

This may well not be a "Gotcha" at all and a simple settings issue in the administrator but I haven't been able to find the "switch" but here it is anyway. Hopefully someone from Railo will be able to correct me if I am wrong.


Installing Railo 3 on Linux (CentOS): Part 1

In a previous post I alluded to how I learn by doing and generally go about it the "hard way". What I learn while sometimes being frustrating tends to settle in my brain and stay longer than if it was a piece of cake. It also allows me to then share with you what I learned and hopefully make life a little bit easier for you. Not everyone likes to do things the hard way.


ColdFusion Camp 2008 Munich

This just in from Christoph Schmitz of the Munich CFUG


Tracking Digital Content

One of our clients an electronic entertainment company provides movie trailers on their site. They also want to provide their partners with a simple EMBED tag for a flash player similar to what youtube does with it videos. Naturally they want to be able to track how often the movie clip or trailer is viewed on their partners sites by using google analytics, or as yet to be determined tracking methods.


When It just Works

Yesterday I spent a bit of time setting up my home machine with Apache, Railo and Resin (I have my PC at work similarly set up but hadn't set up my home machine yet). I have to say that I really like the set-up and by following a few tips by Gert Franz I think I have a pretty good set up that I can move into a production server environment.


EC2 Railo 3 Image Available

If you don't know what EC2 is it's Amazons Elastic Cloud Computing (EC2). It is a service that provides re-sizable compute capacity in the cloud.

There are lot of different public server images available


NACDS or Not Another Coldfusion Dying Story

It seems to me that if you want to drive traffic to your website (and you happen to be a moron) the best way to do it is to post a Top 10 dead (or dying) Computer Skills post.


Railo 3.0 Released

I've been playing around a bit with the Railo 3 beta and have been so far impressed with the performance and features, and the fact that I can run the express version from my USB stick.


Railo 3.0 Not just a Pretty Face

Last night at the Munich CFUG meeting I had the opportunity to meet Gert Franz and Michi Streit from Railo on the last leg of their Whirl Wind Railo World Tour.


Railo Comes to Munich Cfug

Gert Franz and Michi Streit will be visiting the Munich Cfug on the 28th of August to demonstrate and discuss whats new in Railo 3. They have, apparently, also volunteered to sit in the hot seat and answer "all" of our questions with respect to Railo's open source plans.


Rash of Attacks Target Coldfusion

In the last few days there have been a rash of attacks seemly targeted at Coldfusion. More specifically older Coldfusion applications/sites that do not make use of parameterized queries


Var Scoping Queries

Everyone says that we should var scope all of our variables and I make a concerted effort to do just that. But for some reason I've never considered the idea of


Coldfusion CFC Do's and don't's

There are a lot of articles around about coldfusion components; doing a Google search for the term "coldfusion components" brought back just over 160,000 results, that's an awful lot of information to


Coldfusion Database Basics

This isn't about how to write queries, or stored procedures. It's also not about relational databases function or how to properly index. It is about being kind to your database and more efficiently communicating with it.


Railo 3 to become part of JBoss

Well the guys at Scotch really got a real news sweep on the rest of us. I first saw Seans blog entry about Railo 3 and then Rays and I'm still a little flabbergasted.

That makes two open source initiatives of CFML Engines this year, first Open BD and now Railo.


NACFCMS (Not Another CF CMS)

It seems to me that this year is the Year of open source CF CMS's. Ben Forta recently made us aware of ColdBricks open source CF CMS, and now I have stumbled upon Sava CMS. I think it's a great sign to see all of these open source CFM projects coming out, especially in the crowded CMS market.


Capitalize Names Updated

Just a quick note about my Capitalizing Peoples Names post yesterday. I forgot to change the extension of the enclosure to something other than .cfm.

I updated the enclosure and also further optimized my function. You should now be able to download the function.

Happy Coding...

Capitalizing Peoples Names

While doing a code review at work I stumbled accross a horrible piece of code that was written in a hurry, The developer did the best he could at the time with the time that he had available to him to complete the task. He never really had time to think it though so just continued to throw worse code after bad until the problem was eventually solved.

The Problem

There has to be a better way to do what he was doing and so when I got home from work today I decided to actually look at the problem in the context of the system we have.


A Question of Speed

I have been doing some code review lately and am seeing quite a few cases that look something like this:

<cfloop from="1" to="#arrayLen(aData)#" index="i">
<cfquery ....>
<!--- insert query --->

You have a structure with some information in it and you are looping over the structure and adding the data from the structure into the database. No bid deal right?

Well you probably won't be surprised to find out that having a loop around the cfquery tag forces the Coldfusion server to execute that query N number of times, where N is the size of your array.

So what can you do?


TIOBE Reconsiders

After writing my post yesterday about Coldfusion being removed from the TIOBE Index I decided to send an email to TIOBE to question their decision and ask them how they justified their actions on clearly inaccurate information.

This morning I received an email from TIOBE inviting me to check out an addition to their FAQ.

# Q: Who is Richard Bremner? (Bonus question only for this month, especially for the ColdFusion community)


Powered By Railo


Subscribe via RSS
Follow garyrgilbert on Twitter Follow me on Twitter
Or, Receive daily updates via email.


adobe air ajax apple cf community cfml coldfusion examples ext flash flex google javascript jquery max2007 max2008 misc open source programming railo software technology ui

Recent Entries

No recent entries.


An Architect's View
Rey Bango

Wish List

My Wish List