Skip to content

Instantly share code, notes, and snippets.

Created July 15, 2012 21:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save skratchdot/3118727 to your computer and use it in GitHub Desktop.
A ColdFusion function to convert dot notation strings to structs
private struct function convertStringToStruct(required string key, required any value, string delimiter = ".") {
var obj = StructNew();
var first = ListFirst(arguments.key, arguments.delimiter);
var rest = ListRest(arguments.key, arguments.delimiter);
if (Len(rest)) {
obj[first] = convertStringToStruct(rest, arguments.value, arguments.delimiter);
} else {
obj[first] = arguments.value;
return obj;
// Declare a struct. We will later append to this
obj = StructNew();
// Create a few top level keys
obj["ab"] = "foo";
obj["b"] = "bar";
// Append a dynamically created structure
StructAppend(obj, convertStringToStruct("a.b.c", "baz"), false);
// Show our output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment