This project has moved and is read-only. For the latest updates, please go here.

SPXmlToJSON question

Jan 16, 2012 at 6:24 PM
Edited Jan 16, 2012 at 6:31 PM

So how would I use xslt here to change the output of the mapping?  Since we're usually pointing directly to the mapping, wouldn't the data need to be changed prior?  Typically I could work with the output from the list, but I'm not sure how to work with the mapping.

for example...

var author = new String($(this).attr("ows_Author"));
author = author.substring(author.indexOf("#") + 1);

How do I achieve that same result in the mapping now?  Am I making any sense?

Jan 17, 2012 at 2:28 PM


The idea is that you will pass in the XML response from a Web Service, and the SPXmlToJson function will spit back fully formed JSON. In other words, you won't need to do the manipulation above if you don't want to.

In the case of a User field (you need to specify the field type in the mapping):

 function userToJsonObject(s) {
  if(s.length === 0) return null;
  var thisUser = s.split(";#");
  return {userId: thisUser[0], userName: thisUser[1]};

So you'd get back both the ID and the name separately, which you could use as you wish.

Check out the documentation and see if it helps. I'm very interested in suggestions, especially on the optimal format for the JSON for each field type. I really don't want to put something out there that I need to change significantly later, breaking people's existing code. 


Jan 17, 2012 at 4:56 PM



You mention XSLT... In order to use json to generate HTML based on a template (xlst), you will need to change your tool set... so instead of using XSL and XSLT, you can use one of the many jQuery plugins that offer template supports... I currently use jsRepeater, but it looks like the author may have abandoned it (

Microsoft actually contributed a template plugin to jQuery a while back, but looks like it is currently not being maintained (

Looks like jQuery UI will also have one in the future (



Jan 17, 2012 at 5:12 PM

I actually use Telerik's KendoUI tools, and they have a template as part of their framework.  Good call Paul.  Thanks!