Description

Sets metadata for a key in a struct. Use this function when serializing struct data into JSON output.

Returns

Nothing

Category

History

Added in ColdFusion (2016 release) Update 2

See also

Syntax

StructSetMetaData(Struct struct, Struct metadata)

Parameters

Parameters Description
struct (Required) The input structure.
metadata (Required) Metadata to be applied to the struct key(s).

Example

<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>

Output

{"fname":"Yes","lname":"Man","address":{"Street":"123 Any street","House number":"20"}}

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy