By default, Magento returns XML format when you try to access REST API resources. For example :
You try to access REST url to get product’s information of this site : http://localhost/magento/api/rest/products

It will return in XML format.But some cases, other developers want you to send them JSON format instead of XML.

Solution for it is you have to override the METHOD getAccepTypes() in /app/code/core/Mage/Api2/Model/Request.php

to return JSON format by replacing “return array_keys($orderedTypes);”  to  “return array_keys(array(“application/json” => 1));” .

This will help you to Response of REST API in JSON format by default in Magento

There are two ways to do it:

1/You could change it in core file /app/code/core/Mage/Api2/Model/Request.php  : NOT RECOMMENDED
2/ For more professional way, you should create small extension to override Rest Request Model. : RECOMMENDED
Here is how :

2.1/ Declare new module : Create app/etc/modules/Gurutheme_RestConnect.xml

<?xml version="1.0"?>

<config>
<modules>
<Gurutheme_RestConnect>
<active>true</active>
<codePool>local</codePool>
</Gurutheme_RestConnect>
</modules>
</config>

 

2.2/ Create /app/code/local/Gurutheme/RestConnect/etc/config.xml with the following content :

 

<?xml version="1.0"?>

<config>
<modules>
<Gurutheme_RestConnect>
<version>1.0.0</version>
</Gurutheme_RestConnect>
</modules>
<global>
<models>
<Gurutheme_RestConnect>
<class>Gurutheme_RestConnect_Model</class>
</Gurutheme_RestConnect>
<api2>
<rewrite>
<request>Gurutheme_RestConnect_Model_Api2_Request</request>
</rewrite>
</api2>
</models>
</global>
</config>

 

 

As you can see from above code :
We rewrited Mage/Api2/Model/Request by Gurutheme_RestConnect_Model_Api2_Request

 

2.3/ Create /app/code/local/Gurutheme/RestConnect/Model/Api2/Request.php

<?php
class Gurutheme_RestConnect_Model_Api2_Request extends Mage_Api2_Model_Request{

public function getAcceptTypes()
{
$qualityToTypes = array();
$orderedTypes = array();

foreach (preg_split('/,\s*/', $this->getHeader('Accept')) as $definition) {
$typeWithQ = explode(';', $definition);
$mimeType = trim(array_shift($typeWithQ));

// check MIME type validity
if (!preg_match('~^([0-9a-z*+\-]+)(?:/([0-9a-z*+\-\.]+))?$~i', $mimeType)) {
continue;
}
$quality = '1.0'; // default value for quality

if ($typeWithQ) {
$qAndValue = explode('=', $typeWithQ[0]);

if (2 == count($qAndValue)) {
$quality = $qAndValue[1];
}
}
$qualityToTypes[$quality][$mimeType] = true;
}
krsort($qualityToTypes);

foreach ($qualityToTypes as $typeList) {
$orderedTypes += $typeList;
}

return array_keys(array("application/json" => 1));
}

}

 

That’s done. Hope it helps.