JSON and Wordpress

If you want to encode/decode JSON within/using wordpress, you can take a look at

/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php

This file has Moxiecode_JSON class which can do that for you.

Sample code

require_once(ABSPATH."/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php");
$json_obj = new Moxiecode_JSON();
/* encode */
$json = $json_obj->encode(array("key1"=>"value1","key2"=>"value2"));
//$json should have {"key1":"value1","key2":"value2"}
/* decode */
$json_array = $json_obj->decode($json);
//$json_array will be an array("key1"=>"value1","key2"=>"value2")

Tags: , , , ,

6 Responses

  1. Encoding JSON with WordPress « planetOzh:

    [...] more details and examples on KAPISH. Share [...]

  2. JamesD:

    Thanks for the useful info. It’s so interesting

  3. Lee T.:

    This blog makes me want to start my own blog.

  4. Peter:

    Perfect – after struggling through the various json libraries looking for one that would likely be compatible with the majority of wordpress installs (for a plugin), I happened on this – exactly what I was looking for. Thanks!

  5. Archie Hill:

    Wordpress is the best blogging platform ever. It is much better than Typepad and blogspot.”–

  6. Vanessa Bennett:

    i host 5 of my blogs on Blogspot and it is really good for beginners. but if you want something with more features, nothing beats wordpress~*,

Leave a Reply