With the popularity of jQuery, AJAX, and client-side programming operations in general, there’s more use made of JSON as a format for getting data backwards and forwards.
For example, the Twitter API offers data as JSON – and more manageably than accessing their RSS XML feeds for user timelines etc.
http://twitter.com/status/user_timeline/USERNAME.json?count=10
The issue is how to make use of JSON-encoded information in the WordPress environment – much of what is available is only recently available, so some care has to be taken about how it’s used.
1. Native PHP functions
json_encode() and json_decode() make life very simple – but these functions are only available in PHP >= 5.2.0 and WordPress is still designed to run on significantly older versions of PHP than this. Alternatives would have to be supplied if you were thinking about releasing a plugin. There are custom-written functions to reproduce these in PHP4, see for example user contributions to json_encode. These are often not 100% perfect, but one may well do all that you require…
2. JSON2
If you’re happy to do the work in jQuery/javaScript, WordPress 2.9 comes with JSON2 bundled, registered and ready to go…
add_action('wp_print_scripts','load_json_parser');
function load_json_parser(){
if (is_admin()) return; // probably don't want this on admin pages
wp_enqueue_script('json2');
}
No need any more to play around with eval in the javaScript, but again, this is a WordPress >= 2.9 thing….
3. Borrowing the Text Editor
Lastly, there is one more, slightly unofficial, dodge that can be used. WordPress makes use of TinyMCE as its rich text editor and this comes with the its own JSON parser. Results may not be completely predictable.
require_once(ABSPATH."/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php");
$jsObj = new Moxiecode_JSON();
// encodes the supplied array to JSON format
$json = $jsObj->encode(array("key1"=>"value1","key2"=>"value2"));
//decodes supplied JSON to a PHP array
$json_array = $jsObj->decode($json);



