CFLib.org – Common Function Library Project

LCaseStructKeys(str)

Last updated August 26, 2012

author

Steve 'Cutter' Blades

Version: 1 | Requires: CF5 | Library: UtilityLib

Description:
This method will take a structure and lower case all the keys, including those of inner structures. Handy when creating objects for JSON serialization.

Return Values:
Returns a struct with its keys lower-cased

Example:

REQUEST.tmp = {
	"ATEST" = "first test val",
	"anotherTest" = "second test val",
	"WeKeepTesting" = {
		"firstInnerStructKey" = "third test",
		"secondInnerSTRUCTKEY" = {
			"ANOTHERKEY" = "Fourth test Val"
		}
	}
};
WriteOutput(SerializeJSON(LCaseStructKeys(REQUEST.tmp)));

Parameters:

Name Description Required
str Struct to lower-case the keys of Yes

Full UDF Source:

/**
 * Lower Case Structure Keys
 * version 1.0 by Steve 'Cutter' Blades
 * 
 * @param str 	 Struct to lower-case the keys of (Required)
 * @return Returns a struct with its keys lower-cased 
 * @author Steve 'Cutter' Blades (no.junk@cutterscrossing.com) 
 * @version 1, August 26, 2012 
 */
function LCaseStructKeys(str){
	var i = "";
	var tmp = {};
	for(i in str){
		if(isStruct(str[i])){
			str[i] = LCaseStructKeys(str[i]);
		}
		tmp[LCase(i)] = duplicate(str[i]);
	}
	return tmp;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson