<?xml version="1.0" encoding="utf-8"?>
			
			<rss version="2.0">
			<channel>
			<title>Escape Keys - UDFs</title>
			<link>http://www.escapekeys.com/blog</link>
			<description>A ColdFusion and Web Development Blog by Tom de Manincor</description>
			<language>en-us</language>
			<pubDate>Wed, 08 Sep 2010 13:55:19 -0400</pubDate>
			<lastBuildDate>Tue, 15 Apr 2008 20:40:00 -0400</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>blog@escapekeys.com</managingEditor>
			<webMaster>blog@escapekeys.com</webMaster>
			
			<item>
				<title>UDF - flattenStruct() - build nested structs into a single struct</title>
				<link>http://www.escapekeys.com/blog/2008/4/15/UDF--flattenStruct--builded-nested-structs-into-single-struct</link>
				<description>
				
				I whipped this up to contribute to Rolando&apos;s &lt;a href=&quot;http://environmentConfig.riaforge.org&quot;&gt;environmentConfig&lt;/a&gt; project.

ColdSpring doesn&apos;t like being passed complex values, and it&apos;s not that big of a deal unless you are parsing settings from a 3rd party XML, that builds them into a nested struct.

So we came up with this to build all the nested structs into a single struct.
By default it adds the parent struct&apos;s key as a prefix. This is to assure no values are overwritten.

I didn&apos;t see a UDF on CFLib for it, so I figured I&apos;d submit and post here in case it can help anyone else out.

&lt;code&gt;
&lt;cffunction name=&quot;flattenStruct&quot; access=&quot;public&quot; output=&quot;false&quot; returntype=&quot;struct&quot;&gt;
	&lt;cfargument name=&quot;stObject&quot;  required=&quot;true&quot;  type=&quot;struct&quot; /&gt;
	&lt;cfargument name=&quot;delimiter&quot; required=&quot;false&quot; type=&quot;string&quot; default=&quot;.&quot; /&gt;
	&lt;cfargument name=&quot;prefix&quot; 	 required=&quot;false&quot; type=&quot;string&quot; default=&quot;&quot; /&gt;
	&lt;cfargument name=&quot;stResult&quot;  required=&quot;false&quot; type=&quot;struct&quot; default=&quot;#structNew()#&quot; /&gt;
	&lt;cfargument name=&quot;addPrefix&quot; required=&quot;false&quot; type=&quot;boolean&quot; default=&quot;true&quot; /&gt;
	
	&lt;cfset var sKey = &apos;&apos; /&gt;
	
	&lt;cfloop collection=&quot;#arguments.stObject#&quot; item=&quot;sKey&quot;&gt;		
		&lt;cfif isSimpleValue(arguments.stObject[sKey])&gt;
			&lt;cfif arguments.addPrefix and len(arguments.prefix)&gt;
				&lt;cfset arguments.stResult[arguments.prefix &amp; arguments.delimiter &amp; sKey] = arguments.stObject[sKey] /&gt;
			&lt;cfelse&gt;
				&lt;cfset arguments.stResult[sKey] = arguments.stObject[sKey] /&gt;
			&lt;/cfif&gt;
		&lt;cfelseif isStruct(arguments.stObject[sKey])&gt;
			&lt;cfset flattenStruct(arguments.stObject[sKey],arguments.delimiter,sKey,arguments.stResult) /&gt;	
		&lt;/cfif&gt;
	&lt;/cfloop&gt;
	&lt;cfreturn arguments /&gt;
&lt;/cffunction&gt;
&lt;/code&gt; 
				</description>
				
				<category>ColdFusion</category>				
				
				<category>UDFs</category>				
				
				<category>Coldspring</category>				
				
				<pubDate>Tue, 15 Apr 2008 20:40:00 -0400</pubDate>
				<guid>http://www.escapekeys.com/blog/2008/4/15/UDF--flattenStruct--builded-nested-structs-into-single-struct</guid>
				
			</item>
			</channel></rss>