Categories
Magento

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]

3 replies on “Magento’s Core JSON Encoding and Decoding Functions”

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

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.

Comments are closed.