Whatever message this page gives is out now! Go check it out!

StructSetMetaData

Last update:
May 18, 2026

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

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page