Magento’s Core JSON Encoding and Decoding Functions

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

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


Comments

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.