Magento – Returning JSON (for AJAX and API Calls) Response From Controller Action

Within your Magento Controller > Action you can use the below code to send a JSON response.

[php]
$this->getResponse()->setHeader(‘Content-type’, ‘application/json’);
$this->getResponse()->setBody($jsonData);
[/php]

Read this post on how to use Magento’s core helper to encode and decode JSON.