#JavaScript Object Notation (JSON) and CFML
###Creating JSON object
As you probably guessed JSON objects can be created from cf structures
<cfset myStruct = {
items: {
item1: {name: 'item1', price: 1000},
item2: {name: 'item2', price: 12.50},
itme3: {name; 'itme3', price: 15000}
},
users: {
user1: {id: 1, email: '[email protected]'},
user2: {id: 2, email: '[email protected]'},
user3: {id: 3, email: '[email protected]'}
}
} />
<!--- parse the struct into a JSON object --->
<cfset myJSON = serializeJSON(myStruct) />
Because the keys in the key/value pair waren't declared as strings the serializerJSON would change the case to upcase. So to keep the letter case that you want they keys should be declared as strings.
###Convert JSON to Structure
<cfset myJsonStruct = deserializeJSON(myJSON) />
###Validate String as JSON
<cfdump var="#isJson(myJSON)#" />