JSON
CFML supports native JSON support via several key functions and some member functions.

Core Functions

The core functions that deal with JSON are:
Function
Description
deserializeJson(
json
[ , strictMapping ]
[ , useCustomSerializer ]
)
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
isJson( var )
Evaluates whether a string is in valid JSON (JavaScript Object Notation) data interchange format. https://cfdocs.org/isjson
serializeJson(
data
[ , serializeQueryByColumns ]
[ , useSecureJSONPrefix ]
[ , useCustomSerializer ]
)
Converts CFML data into a JSON (JavaScript Object Notation) representation of the data. Only the 'data' argument is required. https://cfdocs.org/serializejson
1
if( isJson( mydata ) ){
2
return deserializeJSON( data );
3
}
4
5
serializeJSON( myQuery, true );
6
serializeJSON( myData );
7
8
person = deserializeJSON( '{"company":"Ortus","name":"Mr OrtusMan"}' );
9
writeOutput( person.company );
Copied!

Member Functions

You can call the deserializeJSON() from any string literal:
1
var deserializedData = myjsonString.deserializeJson();
2
var data = '[]'.deserializeJson();
Copied!
Last modified 2yr ago
Copy link
Edit on GitHub