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




Certified for SharePoint 2007 Certified for SharePoint 2010


SPXmlToJson is a function to convert XML data into JSON for client-side processing.


  mapping: {},
includeAllAttrs: false,
removeOws: true,
sparse: false // Added in 2014.01 });

SPXmlToJson operates on a nodeset from XML returned by a SharePoint Web Services operation. In the current implementation, the nodeset must be "flat", as in the z:row elements retured by GetListItems. In other words, the function doesn't handle any nesting.

An array of columns to return in the JSON. While you should generally limit the values you request in your Web Services calls where you can, in some cases you won't have that capability. This option alows you to create "lean" JSON by only including the attributes you need. You can also rename the attributes for better compatibility with other jQuery plugins, for instance. Where it makes sense, the different column types (SPFieldType) are returned as analogous JavaScript objects. If not specified in the mapping, values are returned as strings.

The default value for mapping is {} (no mappings).

Currently supported objectTypes (SPFieldTypes):

SPFieldType (Type) JavaScript Object Type
Counter int
Integer int
DateTime / datetime Date()
User user = {userId, userName}
UserMulti Array of User
Lookup* lookup = {lookupId, lookupValue}
LookupMulti Array of Lookup
Boolean true / false
MultiChoice Array of strings
Number / float flota
Currency float
Text string object
Attachments** Boolean string ["0", "1"] or Array of urls = {attachment, fileName}
Calculated calculated = {type, value}
URL url = {Url, Description}

Additional formats are:

objectType JavaScript Object Type Comments
JSON [object] Useful when storing text-based JSON in a Single or Multiple line of text column. Added in 2014.01.

* Both the FileRef and FileDirRef have Type="Lookup". I have special cases in the code to parse those two columns out appropriately.

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[i].Url.split(";#")[1];

** By default, the Attachments column simply returns a value indicating whether or not attachments are present ["0", "1"]. If you specify the QueryOption <IncludeAttachmentUrls>TRUE</IncludeAttachmentUrls>, links to the attachments are returned instead.

If true, return all attributes, regardless whether they are in the mapping. The default is false.

Specifically for GetListItems, if true, the leading "ows_" will be stripped from the field name.

If true, empty ("") values will not be returned. The default is false. Added in 2014.01.


This is the simplest example for using SPComplexToSimpleDropdown. You simply provide the nodeset:


In most cases, you'll pass in options which determine the structure of the JSON. Here is an example where I have provided mappings for a number of columns and I'm also including all of the attributes.

var myJson = $(xData.responseXML).SPFilterNode("z:row").SPXmlToJson({
   mapping: {
     ows_ID: {mappedName: "ID", objectType: "Counter"},
     ows_Title: {mappedName: "Title", objectType: "Text"},
     ows_Created: {mappedName: "Created", objectType: "DateTime"},
     ows_Author: {mappedName: "Author", objectType: "User"},
     ows_Country: {mappedName: "Country", objectType: "Lookup"},
     ows_City: {mappedName: "City", objectType: "LookupMulti"},
     ows_Lead_x0020_Source: {mappedName: "LeadSource", objectType: "MultiChoice"},
     ows_Sales_x0020_Rep: {mappedName: "SalesRep", objectType: "UserMulti"},
     ows_Potential_x0020_Value: {mappedName: "PotentialValue", objectType: "Currency"}
    },   // name, mappedName, objectType
   includeAllAttrs: true

The results of the call above look like this, based on my test Sales Opportunities list:


Last edited Mar 12, 2015 at 6:59 PM by sympmarc, version 20


charlienothing Sep 12, 2016 at 8:00 PM 
Hi Marc -

I am using SPXmlToJson along with highcharts to create some visualizations on a page from SP list data. This is working great, but now I am trying to pass a variable from an input form on the page to the mapping section so that the charts being displayed can be modified by user selection. I am struggling with the mapping data being populated by a javascript variable. Any pointers here?

vtang9 Oct 7, 2014 at 2:46 PM 
I was hoping someone can help me here. First question I should probably ask is if this is fully
supported in IE8? Unfortunately, this is still the standard browser in my environment.

My camlQuery is based off of a start and end date based on quarters. So for first quarter 2014, I
see over 3700 results. For some reason, this quarter is returning 0 back. Debugging shows me results
if I place an alert message after the completefunc.

What I've noticed:
Works in Chrome but not IE8 for just first quarter of 2014, other quarters IE8 returns results
At first I thought it had a row limit of sorts but second Quarter actually has more rows, yet that returns data fine in both IE8, Chrome
I included a rowlimit and set that to 100 and it still has a problem. I think it worked with 50 or less as a row limit

My guess is there is a row it does not like and is error for some reason. Putting a debug of true statement did not reveal anything.

Any ideas?

operation: "GetListItems",
async: false,
listName: listName,
CAMLQuery: camlQuery,
completefunc: function (xData, Status)
itemIDArray = $(xData.responseXML).SPFilterNode("z:row").SPXmlToJson({
ows_ID: {mappedName: "ID", objectType: "Counter"}
includeAllAttrs: true,
removeOws: true



//fiddler revealed about 3700+ results but by the time I get here the itemIDArray is 0?

//given the object need to create an array to store the ID
for(i=0; i < itemIDArray.length; i++)

jdhavo Oct 29, 2013 at 2:08 PM 
Can you provide an example on how to parse this in javascript. lookupValue is not valid in JS