Skip to content

Instantly share code, notes, and snippets.

@levonlee
Created July 30, 2015 16:23
Show Gist options
  • Save levonlee/e8aada95114acf0208e6 to your computer and use it in GitHub Desktop.
Save levonlee/e8aada95114acf0208e6 to your computer and use it in GitHub Desktop.
Convert ColdFusion Variable to JSON and Output
<!--- Convert a ColdFusion variable to JSON format --->
<cfset s = "I'm a string or URL.">
<cfset numInteger = 1994>
<cfset JSONUtil = createObject("component","functions.JSONUtil")>
<cfoutput>#JSONUtil.serializeJSON(s)#</cfoutput>
<cfoutput>#JSONUtil.serializeJSON(numInteger,0,1)#</cfoutput>
<!--- Read json --->
<cfset strJson = ' {"strerror":"","strsuccess":"Thank you for your message!"}'>
<cfset JSONUtil = CreateObject("component","functions.JSONUtil") />
<cfset myCFvar= JSONUtil.deserializeFromJson(strJson)>
<cfdump var="#myCFvar#">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment