Encoding an array to JSON is dead easy on PHP 5.2+: you just use PHP's function json_encode(). The thing is, WordPress has pretty loose requirements and is designed to run on older PHP builds. For those, you need a third party library that will encode to (and decode from, if you need) JSON.
The cool news is that you don't have to bother searching for such a reliable library: WordPress comes with its own. Just include() the file located at /wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php and you're good.
Check more details and examples on KAPISH.
Shorter URL
Want to share or tweet this post? Please use this short URL: http://ozh.in/lu
Good find Ozh, that will come in useful for PHP4 compatibility for my API plugin.