DeserializeJSON

Converts a JSON (JavaScript Object Notation) string data representation into CFML data, such as a struct or array.

DeserializeJSON( JSONVar=string, strictMapping=boolean );

Returns: any

Argument Description Default
JSONVar
string, required

A string that contains a valid JSON construct, or variable that represents one.

Alias: json, data

strictMapping
boolean, optional

A Boolean value that specifies how to convert the JSON

  • TRUE Converts JSON structure strictly to CFML, using only JSON Datatypes
  • FALSE Query formats (like SerializeJSON outputs) are converted back to CFML Queries

true

Examples

json = '{
	"stringValue":"a string",
	"arrayValue": ["a","b","c"],
	"booleanValue":true,
	"numericValue": 42
}';
myStruct = deserializeJson(json);
writeDump(myStruct);

Credit to Adam Cameron for suggesting the example

Strict Mapping with Queries

q = queryNew(
        "id,name",
        "numeric,varchar",
        {
            id: [1,2,3],
            name: ['Neo','Trinity','Morpheus']
        }
    );
    dump(q);
    dump( var=deserializeJSON( serializeJSON(q, 'column'),true ),
        label="'strictMapping TRUE'" );
    dump( var=deserializeJSON( serializeJSON(q, 'column'),false ),
        label="'strictMapping FALSE'" );
    q= { nested1: q, nested2: {q3: q} };
    dump( var=deserializeJSON( serializeJSON(q),false ),
        label="'strictMapping FALSE *nested queries*'" );

See also