I recently started messing around with building my own Facebook application. I figured the best way to start learning was to download the demo application and get it working on the Slaptijack web server. I quickly ran into a problem:
PHP Fatal error: Call to undefined function json_encode()
The problem is that PHP 5.2 includes the json_encode() and json_decode() functions built right in. Unfortunately, I’m running on PHP 5.0 which doesn’t include native JSON support. Here’s how I resolved that.
- Install json – This was actually trickier than expected. I assumed I would be able to install this via
pear. Apparently, a PEAR Services_JSON package was developed, but it has never been accepted into the official repository. The trick instead is to use the PECL json package. This was as easy as runningpecl install jsonand watching the compiler do its thing. When it’s done you should have ajson.sofile in your PHP modules directory. (Mine is/usr/lib/php/modules/.) - Add
json.inifile to/etc/php.d/– This file is pretty simple. Simply addextension=json.soto this file and that will enable the extension. - Restart Apache – Not much more to add here. Without the restart, the extension won’t be loaded.
- Profit!
That’s all it took. Now my PHP 5 installation is kicking along happily with the required JSON functions.

Get Slaptijack updates delivered to your Inbox or RSS Reader for free!
[...] Source: http://slaptijack.com/system-administration/lets-install-json-for-php-5/ [...]
Great tutorial.
This information is still valid in 2010 and works wonders for getting certain plugins to work flawlessly with WordPress!! Thanks for the great info!!
until I discovered this tutorial my only option was to upgrade the packages on my RH EL5 server. This would have rendered my server as ‘non-official’ with RedHat Network (a rather large price to pay).
Your solution took 5 mins to implement and worked like a charm.
Thanks Heaps
If you are working on a shared web server which have older php version. You can include jsonwrapper.php file to overcome this. include”jsonwrapper.php” At the top of your code and you’re ready to go.
Here is the location to download jsonwrapper.php file
http://www.boutell.com/scripts/jsonwrapper.html
Hope this will help..:D
thanks dilantha, this is what i were looking for, i will try it and post here the results.
thanks a lot man…it worked for me
Hi,
Thanks a lot for your trick, I am installing glpi on a customer with redhat el 5, the version of php is version 5.1.6, your trick saved my life
Thanks a lot. It works
Glad to hear it!
[...] install JSON in your linux machine, follow these [...]