SPXmlToJson Formatting Question

Sep 26, 2013 at 7:56 PM
Edited Sep 26, 2013 at 8:37 PM
I am currently doing a GetListItems on a photolibrary list where I would like to return the filenames. All is going well however I want to convert this into json.

Currently I have this which is working:
var data = $(xData.responseXML).SPFilterNode("z:row").SPXmlToJson({
                        mapping: {
                            ows_FileLeafRef: { mappedName: "Name", objectType: "Text" },
                            ows_FileRef: { mappedName: "Url", objectType: "Text" }
                        }
My question is, how can I format the value of ows_FileLeafRef to remove the stuff I dont want, in this scenario convert:
10;#Filename.JPG
To:
Filename
I realize I can do this with an $.each() afterwards however I was just wondering if it is possible to do this using the mapping funcitonality.
Coordinator
Sep 26, 2013 at 10:16 PM
I should add some detail for this into the documentation. Both the FileRef and FileDirRef have Type="Lookup". I have special cases in the code to parse those two columns out appropriately.

So this should work for you:
var data = $(xData.responseXML).SPFilterNode("z:row").SPXmlToJson({
                        mapping: {
                            ows_FileLeafRef: { mappedName: "Name", objectType: "Lookup" },
                            ows_FileRef: { mappedName: "Url", objectType: "Lookup" }
                        }
If you would like just the text back so that you can parse it yourself, then stick with objectType: "Text" and parse it using .split():
myFileRef = data.Url.split(";#")[1].split(".")[0]
M.