Copy link to clipboard
Copied
Hello, everyone.
Does anyone have any suggestions on a good way to convert LDAP data into an associative array with the key being the fieldname?
For example:
dn: CN=First Last, OU=Dept A, OU=Dept B, OU=Domain Users,DC=hq,DC=domainname,DC=com
changetype: edit
sn: Last
description: Dept C
telephoneNumber: xxx-xxx-xxxx
givenName: First
empID: ab1234x
There are several thousand similar to the above; some will have three lines of data, some as many as twelve, each individual separated by double line breaks (<br />). I need to make an array where "dn", "changetype", "sn", etc., are the keys with the text after the colon as the value.
What is the best way to do this?
Thank you,
^_^
Copy link to clipboard
Copied
What is the source of the data? Is it a text file with the above data? Is it an LDAP query? Spreadsheet?
Jason
Copy link to clipboard
Copied
Hi, Jason.
Sorry.. I still haven't completely woken up, yet.
The data is in a .ldf file that resides on the server. Right now, I'm using CFFILE to read it into a string. I can also set it up for JavaScript, if that would be easier/quicker/more efficient.
^_^
Copy link to clipboard
Copied
Well.. I pushed ahead, a little, and am trying to manually create an array of arrays. But the nested array is (at least, what I _plan_ for it to be) an associative array. So I'm splitting on the colon ":" and trying to set the left value as the key and the right value as the value.
But I'm getting an error message: The value Dn cannot be converted to a number.
I've tried many things, including ToString, and I just can't seem to nail it.
^_^
Copy link to clipboard
Copied
Inside CFSCRIPT:
for(i=1; i lte arrayLen(ldap_data2); i++){
thisArray = listToArray(ldap_data2,"""",false); thatArray = ArrayNew(1);
for(j=1; j lte arrayLen(thisArray); j++){
thatArray[ListGetAt(thisArray
,1,':')] = thatArray[ListGetAt(thisArray ,2,':')]; }
}
^_^
Copy link to clipboard
Copied
I got it partially figured out. I wasn't using the index of the array as notation. thatArray
However, instead of having an index array of associative arrays, I have an index array of index arrays, each of which contains a single struct that just happens to be an associative struct.
Sigh.. the search continues.. suggestions greatly appreciated.
Thank you,
^_^