Skip to content

Instantly share code, notes, and snippets.

@levonlee
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save levonlee/c39c421ec66c7123d1e2 to your computer and use it in GitHub Desktop.

Select an option

Save levonlee/c39c421ec66c7123d1e2 to your computer and use it in GitHub Desktop.

Output query to json format.

Convert a struct to JSON using this JSONUtil.cfc

<cfset var jUtil = createObject("component", "functions.JSONUtil")
<cfset j = StructNew()>
<cfset j.optionsOther = StructNew()>
<cfloop query="getOptionsOther">
<cfset tempName = trim(getOptionsOther.varKey)>
<!--- Turn key to json format --->
<cfset tempKey = replace(LCase(tempName)," ", "_", "all")>
<cfset tempKey = replace(tempKey,"(", "", "all")>
<cfset tempKey = replace(tempKey,")", "", "all")>
<cfset j.optionsOther[tempKey] = StructNew()>
<cfset j.optionsOther[tempKey].name = tempName>
<cfset j.optionsOther[tempKey].value = trim(getOptionsOther.varValue)>
</cfloop>
<cfset json = '{"optionsOther":' & jUtil.serializeJSON(j.optionsOther) & '}'>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment