Examples

Encoding

<cfscript>
    thestruct = StructNew();
    thestruct["realstring"] = "this is a real string";
    thestruct["integer"] = 1234;
    thestruct["FLOAT"] = 2.334;
    thestruct["substruct"] = structnew();
    thestruct.substruct["what"] = "this";
    thestruct.substruct["what1"] = "this";
    thestruct.substruct["what2"] = "this";
    thestruct.substruct["myarray"] = arraynew(1);
    thestruct.substruct.myarray[1] = "first";
    thestruct.substruct.myarray[2] = "second";
    thestruct.substruct.myarray[3] = "third";
    thestruct.substruct.myarray[4] = 'the fourth has a " quote in it, as well as a comma';
    thestruct.substruct.myarray[5] = arraynew(1);
    thestruct.substruct.myarray[5][1] = "sub-1";
    thestruct.substruct.myarray[5][2] = "sub-2";
    thestruct.substruct.myarray[5][3] = "sub-3";
</cfscript>

<cfinvoke component="JSON" method="encode" data="#thestruct#" returnvariable="result" />

<cfoutput>#result#</cfoutput>

Output:
{"realstring":"this is a real string","FLOAT":2.334,"substruct":{"what2":"this","myarray":["first","second","third","the fourth has a \" quote in it, as well as a comma",["sub-1","sub-2","sub-3"]],"what":"this","what1":"this"},"integer":1234}

Decoding

<cfset input_string = '{key1:"string value",key2:["array","of","elements"],key3:123}' />

<cfinvoke component="JSON" method="decode" data="#input_string#" returnvariable="result" />

<cfdump var="#result#">

Output:

struct
key1 string value
key2
array
1 array
2 of
3 elements
key3 123