SPXmlToJson - float values

Jun 19, 2012 at 8:45 PM
Edited Jun 19, 2012 at 8:47 PM

I recently encountered a problem where I'm trying to extract float values from a SharePoint list. Below is a small sample of the raw xml data I get from the "GetListItems" SPService operation.


<rs:data ItemCount="10" ListItemCollectionPositionNext="Paged=TRUE&amp;p_ID=82605">
   <z:row ows_Rpt_Date='datetime;#2012-04-29 00:00:00' ows_Interval='float;#5.00000000000000' ows_First_x0020_Responder='rs7903' ows_First_Closer='ah9215' ows_Alert_ID='300975.000000000' ows_Time_x0020_to_x0020_Acknowledge_='20.0000000000000' ows_Closed_Count='1.00000000000000' ows__ModerationStatus='0' ows__Level='1' ows_ID='82596' ows_owshiddenversion='1' ows_UniqueId='82596;#{90CBF022-DEDB-42B2-94D9-AAC03E577BE3}' ows_FSObjType='82596;#0' ows_Created='2012-05-06 12:11:01' ows_Alert_x0020_Created_x0020_Time='2012-04-29 00:20:03' ows_FileRef='82596;#sites/U-SPOC/DSLAM/Lists/VRAD_Alerts_List/82596_.000' ows_MetaInfo='82596;#' />
   <z:row ows_Rpt_Date='datetime;#2012-04-29 00:00:00' ows_Interval='float;#5.00000000000000' ows_First_x0020_Responder='rs7903' ows_First_Closer='rt2761' ows_Alert_ID='300977.000000000' ows_Time_x0020_to_x0020_Acknowledge_='27.0000000000000' ows_Closed_Count='2.00000000000000' ows__ModerationStatus='0' ows__Level='1' ows_ID='82597' ows_owshiddenversion='1' ows_UniqueId='82597;#{A00E37F2-0906-413E-9BEA-2366B9F70519}' ows_FSObjType='82597;#0' ows_Created='2012-05-06 12:11:01' ows_Alert_x0020_Created_x0020_Time='2012-04-29 01:40:01' ows_FileRef='82597;#sites/U-SPOC/DSLAM/Lists/VRAD_Alerts_List/82597_.000' ows_MetaInfo='82597;#' />
   <z:row ows_Rpt_Date='datetime;#2012-04-29 00:00:00' ows_Interval='float;#5.00000000000000' ows_First_x0020_Responder='rs7903' ows_First_Closer='rt2761' ows_Alert_ID='300978.000000000' ows_Time_x0020_to_x0020_Acknowledge_='30.0000000000000' ows_Closed_Count='1.00000000000000' ows__ModerationStatus='0' ows__Level='1' ows_ID='82598' ows_owshiddenversion='1' ows_UniqueId='82598;#{F9A5D446-130E-44E2-850D-9B3BCF75E395}' ows_FSObjType='82598;#0' ows_Created='2012-05-06 12:11:01' ows_Alert_x0020_Created_x0020_Time='2012-04-29 01:40:01' ows_FileRef='82598;#sites/U-SPOC/DSLAM/Lists/VRAD_Alerts_List/82598_.000' ows_MetaInfo='82598;#' />


When using SPXmlToJson to make this into a JSON object, there's no method that'll convert "ows_Interval" into a proper float. Trying the usually "Float" or even "Integer" just return a NaN value.

While I can easily work around this by bringing it in as a string them parsing the value myself.. I thought it may be useful to post a possible fix to help any future users with this error. 

I suggest the following change to the "floatToJsonObject" function within the SPServices source.


function floatToJsonObject(s) {
  return parseFloat(s.replace('float;#', ''));


The replace function will get rid of that nasty 'float;#' prefix and allow parseFloat to work as intended.

::edit:: removed a lot of the XML responses to shorten things up.


Jun 19, 2012 at 10:15 PM


It looks like Interval (and Rpt_Date) are Calculated columns. You should take advantage of the mapping option to improve the results that SPXmlToJson gives you.

There's already a fix in v0.7.2ALPHA5 to handle Calculated columns with mappings. Give it a try and see if it solves the problem for you.


Jun 20, 2012 at 12:51 PM


So I downloaded v0.7.2ALPHA5 and gave it a try.. while I was a little confused that setting the objectType as "float" didn't work.. a quick skim over the source code helped me find and use "Calc" with great success!


Jun 20, 2012 at 1:11 PM

Great! Yeah, sorry about that. I haven't updated the docs yet, since that functionality isn't available in the released version. Actually, "float" should probably have worked.