CFML supports native JSON support via several key functions and some member functions.
The core functions that deal with JSON are:
Function | Description |
| Converts a JSON (JavaScript Object Notation) string data representation into CFML data, such as a struct or array. Only the 'json' argument is required. https://cfdocs.org/deserializejson​ |
| Evaluates whether a string is in valid JSON (JavaScript Object Notation) data interchange format. https://cfdocs.org/isjson​ |
| Converts CFML data into a JSON (JavaScript Object Notation) representation of the data. Only the 'data' argument is required. https://cfdocs.org/serializejson​ |
if( isJson( mydata ) ){return deserializeJSON( data );}​serializeJSON( myQuery, true );serializeJSON( myData );​person = deserializeJSON( '{"company":"Ortus","name":"Mr OrtusMan"}' );writeOutput( person.company );
You can call the deserializeJSON()
from any string literal:
var deserializedData = myjsonString.deserializeJson();var data = '[]'.deserializeJson();