Parameters
Sets metadata for a key in a struct. Use this function when serializing struct data into JSON output.
Nothing
Added in ColdFusion (2016 release) Update 2
StructSetMetaData(Struct struct, Struct metadata)
|
Parameters |
Description |
|
struct |
(Required) The input structure. |
|
metadata |
(Required) Metadata to be applied to the struct key(s). |
<cfscript>
example = structnew("ordered");
example.firstname = "Yes";
example.lastname = "Man";
example.address={"Street":"123 Any street","House":"20"};
// changing the default serialization by specifying the type of "firstname" as string
metadata = {firstname: {type:"string",name:"fname"},lastname:{name:"lname"},address:{keys:{"house":{type:"string",name:"House number"}}}};
StructSetMetaData(example,metadata);
writeoutput(SerializeJSON(example) & "<br/>");
</cfscript>
{"fname":"Yes","lname":"Man","address":{"Street":"123 Any street","House number":"20"}}
Sign in to your account