Magento’s Core JSON Encoding and Decoding Functions

To JSON encode an array
$jsonData = Mage::helper(‘core’)->jsonEncode($array);

To JSON decode an array
$array = Mage::helper(‘core’)->jsonDecode($jsonData);


3 responses to “Magento’s Core JSON Encoding and Decoding Functions”

  1. Stephen Johnston

    Out of curiosity what is the advantage to using this over simply calling Zend_Json::encode/decode()?

    1. You can do that! That should work. The idea is to stay within Magento’s scope as much as possible.

    2. There is a difference, when using the core magento helper the json data gets passed through the inline translator (if enabled) so your strings will get translated, if you use Zend_Json directly it won’t.