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

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson