I made a customer log-in to the site programmatically... I am properly returned the session values in form of an object.

Now i want this data carried over and returned from the function in JSON format.

I know magento has its own encoding and decoding functions... But this conversion does not some how take place properly.

I mean session object contains customer's email, first, last name,etc. But these are not reflected in converted json... So how do I convert this properly??

Thanks in advance

Here is my code..


function loginUser( $email, $password )
    require_once ("../../app/Mage.php");
    Mage::getSingleton("core/session", array("name" => "frontend"));

    $websiteId = Mage::app()->getWebsite()->getId();
    $store = Mage::app()->getStore();
    $customer = Mage::getModel("customer/customer");
    $customer->website_id = $websiteId;
    try {
        $session = Mage::getSingleton('customer/session');
        $session->login($email, $password);
        $jsonData = Mage::helper('core')->jsonEncode($session);

    }catch(Exception $e){
        return $e->getMessage();


    $test = loginUser("test1.igex@gmail.com","testigex");
  • I can't help, but little tip: add in your question what you're really getting as opposed to what you want to get. Makes the question more understandable – Yorrd May 13 '15 at 8:05

It is not good idea to return a php object to json value.As per as,php concept json is convert a string varible and an array of string variables to json object.

Json does not capable to convert a php to json object.

If you want data then need to return customer data in array format.

just like:

$jsonData = Mage::helper('core')->jsonEncode($customer->getData());

getData() is give Customer data in array format.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.