2 Replies Latest reply: Jul 24, 2012 12:50 PM by Charlie Arehart RSS

    SerializeJSON

    Community Help Community Member
        • 1. Re:  SerializeJSON
          Charlie Arehart CommunityMVP

          Adding to the "note" above, for those who are annoyed by the fact that CF creates capitalized names of the variables, in the json-formatted result, you can solve that with a workaround. For instance, if you were serializing a struct named get with a variable named fname, then rather than set it as cfset get.fname="bob", you will find that if you do cfset get["fname"]="bob", that will create a lowercase variable name in the json output.

          • 2. Re:  SerializeJSON
            Charlie Arehart CommunityMVP

            Also, if perhaps there are other issues with what the function creates, you may want to consider any of many alternatives (for serializing to json from within cfml).

             

            For instance, one is the UDF (user defined function) called jsonencode(), found on the cflib.org site and created by Jehiah Czebotar, http://www.cflib.org/udf/jsonencode. It's a pretty big function, and was written for CF 6, so it may not perform as optimally as CF's built-in function, but I had one user for whom it worked better (especially in terms of handling dates, compared to the CF built-in function). As always, do testing to confirm its suitability for yourself. There is a corresponding jsondecode as well.

             

            One could also ue a Java-based approach, and in fact Jehiah (and others) created another open source solution at http://www.epiphantastic.com/cfjson/.

             

            I'm not proposing that people should use these alternatives rather than the built-in function. I'm just pointing out, as I did for a client, that there are indeed alternatives if something about the built-in function doesn't work for you. If they solve that for you, great. And then raise any concerns about the current function to Adobe as needed (https://bugbase.adobe.com/).