I need to convert the response from magento SOAP API to json, How to achieve this, Here is the code
$proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey'); 
$result = $proxy->catalogProductList($sessionId);
var_dump($result);
 - 
 You can get help here : php.net/manual/en/function.json-decode.phpArunendra– Arunendra2016年02月29日 11:18:27 +00:00Commented Feb 29, 2016 at 11:18
 
2 Answers 2
If you want to send json data back from magento end you need to overwrite each function in magento API
For Example catalogProductList() method
Copy file
app/code/core/Mage/Catalog/Model/Product/Api.php
To
app/code/local/Mage/Catalog/Model/Product/Api.php
And modify below function
public function items($filters = null, $store = null)
{
 $collection = Mage::getModel('catalog/product')->getCollection()
 ->addStoreFilter($this->_getStoreId($store))
 ->addAttributeToSelect('name');
 /** @var $apiHelper Mage_Api_Helper_Data */
 $apiHelper = Mage::helper('api');
 $filters = $apiHelper->parseFilters($filters, $this->_filtersMap);
 try {
 foreach ($filters as $field => $value) {
 $collection->addFieldToFilter($field, $value);
 }
 } catch (Mage_Core_Exception $e) {
 $this->_fault('filters_invalid', $e->getMessage());
 }
 $result = array();
 foreach ($collection as $product) {
 $result[] = array(
 'product_id' => $product->getId(),
 'sku' => $product->getSku(),
 'name' => $product->getName(),
 'set' => $product->getAttributeSetId(),
 'type' => $product->getTypeId(),
 'category_ids' => $product->getCategoryIds(),
 'website_ids' => $product->getWebsiteIds()
 );
 }
 return Mage::helper('core')->jsonEncode($result); 
}
 - 
 Thanks for the response.. I have added the code but no data is fetched the output i am getting is array(0) { }vellai durai– vellai durai2016年02月29日 11:56:00 +00:00Commented Feb 29, 2016 at 11:56
 - 
 You have products in your shop?Minesh Patel– Minesh Patel2016年02月29日 12:01:45 +00:00Commented Feb 29, 2016 at 12:01
 - 
 yes.. The output of the default code is array(1429) { [0]=>vellai durai– vellai durai2016年02月29日 12:03:16 +00:00Commented Feb 29, 2016 at 12:03
 - 
 Copy original function items () from core file and just replace return statementMinesh Patel– Minesh Patel2016年02月29日 12:07:25 +00:00Commented Feb 29, 2016 at 12:07
 - 
 Getting same outputvellai durai– vellai durai2016年02月29日 12:10:18 +00:00Commented Feb 29, 2016 at 12:10
 
To decode JSON into an array you can use the following code:
$array = Mage::helper('core')->jsonDecode($result);
To encode an array into JSON you can use the following code:
$json = Mage::helper('core')->jsonEncode($result);