TIBCO Spotfire® Statistics Services Users Guide

Return results as JSON

If you are building a web application that uses JavaScript or Java, you can set up Spotfire Statistics Services to return results in the JavaScript Object Notation (JSON) format rather than in the XML format (the default).

For more information about JSON, see http://www.json.org/.

To get your results in JSON, specify a standard HTTP accept header value of "application/json".

The JSON object that Spotfire Statistics Services returns is equivalent to the SPXML, except the XML elements become JSON objects (or arrays of objects, if more than one XML element of the same name is included), and XML attributes become object properties.

Note: To use JSON, you must make sure that property names generated are compliant with JSON rules. That is, to return valid properties, check that any hyphen or dash ("-") is replaced by an underscore ("_").

Example

The following XML output example is the results of sending to Spotfire Statistics Services the expression "1:10":

<SplusDataResult version="1.0" createdBy="nobody" serverTime="309" scheduledMillis="1441915267457" prepTime="0" createdMillis="1441915267457" status="2" serverInstance="jdoe-X240" scheduled="Thu Oct 7 13:01:07 PDT 2021" queueCount="0" percent="0.0" jobId="38" hasWarnings="false" hasTextOutput="true" hasReturnValue="true" hasError="false" engineTime="34" created="Thu Sep 10 13:01:07 PDT 2015">
<Code>1:10</Code>
<SplusReturnValue>
<TERR>
<DisplayOptions decimalPattern="#,##0.00" scientificPattern="0.00E0"/>
<Header>
<Application name="TERR" version="TIBCO Enterprise Runtime for R version 6.0.0 (2021-10-07)"/>
<Timestamp>Thu Oct 7 13:01:07 2021</Timestamp>
</Header>
<Vector length="10" type="integer">
<Items>
<Item>1</Item>
<Item>2</Item>
<Item>3</Item>
<Item>4</Item>
<Item>5</Item>
<Item>6</Item>
<Item>7</Item>
<Item>8</Item>
<Item>9</Item>
<Item>10</Item>
</Items>
</Vector>
</TERR>
</SplusReturnValue>
<SplusTextOutput>
<![CDATA[ **** Engine execution output **** ]]>
</SplusTextOutput>
<ResultsDir>
http://jdoe-X240:8080/SplusServer/webdav/results/73FD0479F352EC49/
</ResultsDir>
</SplusDataResult>

The JSON output from the same execution, appears as follows:

{"SplusDataResult":
    {"SplusTextOutput":"\n\t\t**** Engine execution output ****\n ... Type 'q()' to quit R.\n\t",
    "scheduledMillis":"1363287836030",
    "ResultsDir":"http://jdoe-X240:8080/SplusServer/webdav/results/DB303112E91DE7/",
    "jobId":"307",
    "queueCount":"0",
    "createdMillis":"1260830585143",
    "status":"2",
    "serverInstance":"jdoe-X240",
    "SplusReturnValue":{"TERR":
        {"DisplayOptions":{"decimalPattern":"#,##0.00","scientificPattern":"0.00E0"},
            "Vector":{"Items":{"Item":["1","2","3","4","5","6","7","8","9","10"]},"length":"10","type":"integer"}}},
    "engineTime":"23","Code":"1:10",
    "hasTextOutput":"true",
    "hasReturnValue":"true",
    "version":"1.0",
    "scheduled":"Thu Oct 7 13:08:00 PDT 2021”,
    "createdBy":"user1","created":"Thu Oct 7 13:03:12 PDT 2021",
    "hasError":"false",
    "serverTime":"90",
    "hasWarnings":"false"}}

JavaScript example (Dojo-specific)

The following JavaScript example demonstrates setting the server to return results as JSON.

Note: This example uses Dojo, a javascript framework for constructing interactive browser applications. Write your code for the framework you use.
function loadJobDetails(nodeSelected){
   if (nodeSelected == undefined) return;
   dojo.xhrGet( {
         url: 
          "http://localhost:8080/TERRServer/api/v8/jobs/" +
           nodeSelected,
         handleAs: "json",
         headers: {accept: "application/json",
                Authorization:
                 connectionInfo.getBasicAuthentication()},
         preventCache: true,
         load: function(response)
        {
               //handle success
        },
        error: function(response) {
              //handle errors
       }
   }); // end dojo.xhrGet
}