Search This Blog

Friday, May 31, 2013

ColdFusion: Working with JSON

JSON has been gaining popularity to represent data in JavaScript applications. Below is an example of JSON data with some array and a ColdFusion parse function to convert JSON data to ColdFusion structure.

<cfsavecontent variable="personnel_record">
{
 "firstname": "John",
 "lastname": "Smith",
 "age": 36,
 "address": {
  "number": "12345",
  "street": "Any Street",
  "city": "Any City",
  "state": "AA",
  "zip": "90876"
 },
 "children": [
  {
   "firstname": "Ian",
   "age": 7,
   "married": false
  },
  {
   "firstname": "Heather",
   "age": 6,
   "married": false
  }
 ]
}
</cfsavecontent>

<cfdump var="#deserializeJSON(personnel_record)#" />

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.