Skip to content
Permalink
Fetching contributors…
Cannot retrieve contributors at this time
83 lines (72 sloc) 2.33 KB

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
Here are some examples for you:
if( isJson( mydata ) ){
    return deserializeJSON( data );
}

serializeJSON( myQuery, true );
serializeJSON( myData );

person = deserializeJSON( '{"company":"Ortus","name":"Mr OrtusMan"}' );
writeOutput( person.company );

Member Functions

You can call the deserializeJSON() from any string literal:

var deserializedData = myjsonString.deserializeJson();
var data = '[]'.deserializeJson();
You can’t perform that action at this time.