coldfusion and JSON
i want to take a query and format it into JSON. i'm looking at the SerializeJSON function but for whatever reason CF is putting the result in a strange format not consistent with JSON.
For example this query:
<cfquery name="data" datasource="dSource">
SELECT first_name, last_name
from emps
where 1= 1
and fiscal_yr = 2012
group by last_name, first_name
ORDER BY last_name
</cfquery>
theJSON = SerializeJSON(data)
the value of theJSON is something like:
{"COLUMNS":["FIRST_NAME","LAST_NAME"],"DATA":[["Doe","John"],["Smith","Jane"],["Patel","Joe"]]}
but I want it like this (in the standard JSON format):
{
"items": [
{
"first_name": "Doe",
"last_name": "John"
},
{
"first_name": "Smith",
"last_name": "Jane"
},
{
"first_name": "Patel",
"last_name": "Joe"
}
]
}
how can this be accomplished without writing something tedious like this:
{
"items": [
<cfoutput query="data">
{
"first_name": "#first_name#",
"last_name": "#last_name#"
}<cfif currentrow neq data.recordcount>,<cfelse>]</cfif>
</cfoutput>
}
