[MarkLogic Dev General] rest services return xml instead of json

Geert Josten Geert.Josten at marklogic.com
Thu Feb 2 00:54:49 PST 2017

Hi Jothi,

The outputTypes only influences the Content-type header(s), not causes output to get formatted automatically. I recommend making sure you really return a JSON object in your REST extension (e.g. object-node() or a true JavaScript JSON object), or convert your result to JSON string. You might wanna look into xdmp.toJSON, xdmp.toJsonString, json.transformToJson (you need to import the xqy module of json:transform-to-json for this), or if working with database nodes $mynode.toObject()..


From: <general-bounces at developer.marklogic.com<mailto:general-bounces at developer.marklogic.com>> on behalf of "Vinayagam, Jothiprakash (Conduent)" <Jothiprakash.Vinayagam at conduent.com<mailto:Jothiprakash.Vinayagam at conduent.com>>
Reply-To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Date: Thursday, February 2, 2017 at 1:17 AM
To: "'general at developer.marklogic.com<mailto:'general at developer.marklogic.com>'" <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Subject: [MarkLogic Dev General] rest services return xml instead of json

HI all,

We wrote rest service below to get the data. It returns as xml instead of json

<?xml version="1.0" encoding="UTF-8"?>
<json:array xmlns:json="http://marklogic.com/xdmp/json" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <json:entry key="2017-01">
               <json:entry key="">
                 <json:value xsi:type="xs:integer">24309</json:value>

function get(context, params) {
    context.outputTypes = [];

    var date = (typeof params.fromDate === 'undefined') ? null : params.fromDate;
    var endDate = (typeof params.toDate === 'undefined') ? null : params.toDate;
    var doNum = (typeof params.doNum === 'undefined') ? null : params.doNum;
    var ldssID = (typeof params.ldssID === 'undefined') ? null : params.ldssID;
    console.log("testing" + params.fromDate);
    console.log("testing" + params.toDate);

// some code


Rest service called from controller:

            MLRest.extension('abawdDashboard', {
                method: 'GET',
                params: { 'rs:fromDate': fromDateRunReport, 'rs:toDate': toDateRunReport, 'rs:doNum': $scope.dashboard.doID, 'rs:ldssID': $scope.dashboard.ldssID }
            }).then(function(response) {
                console.log("run report" + response.data);
                $scope.indexedObjects = response.data;
                $scope.dashBoardData = response.data;
                var curYear = new Date();
                populateCount(fromDateRunReport, toDateRunReport, response.data);
                //$rootScope.$emit('rootScope:emit', 'Emit!'); // $rootScope.$on
                //$rootScope.$broadcast('rootScope:broadcast', response.data);
                //$scope.indexedObjects = indexByAttribute(response.data);

Note: same working fine in my local if I deploy dev/test it returning xml instead of json

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20170202/a7dc23fb/attachment-0001.html 

More information about the General mailing list