Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Im trying to use json with php and i keep getting the error

PHP Fatal error: Call to undefined function json_encode()

I am using php version 5.3.6 and on phpinfo(); nothing mentions json. Any suggestions?

share|improve this question

migrated from stackoverflow.com Sep 6 '11 at 18:32

This question came from our site for professional and enthusiast programmers.

    
Try installing: pecl.php.net/package/json –  stslavik Sep 6 '11 at 17:02
    
@stslavik When i try installing it says ` cannot install: doesn't work with PHP version : 5 (Doesn't support PHP 5 52)` –  Jonah Katz Sep 6 '11 at 17:06

3 Answers 3

up vote 3 down vote accepted

For some reason your PHP was compiled without JSON. Either:

share|improve this answer

try in shell (assuming you are using linux),
otherwise refer to phpinfo();

php -i | grep json

example

php -i | grep json
json
json support => enabled
json version => 1.2.1

There is an interesting comment on the docs http://www.php.net/manual/en/json.requirements.php

If you're not seeing the json functions on 5.2.0 or newer, make sure php wasn't compiled with --disable-json

share|improve this answer
    
I keep seeing this around.. where do i run --disable-json? –  Jonah Katz Sep 6 '11 at 17:06
    
you should delete this question :) –  ajreal Sep 6 '11 at 17:10
    
Cant if theres already answers :/ –  Jonah Katz Sep 6 '11 at 17:11

If you're on Debian/Ubuntu, try:

apt-get install php5-json

and then

service php5-fpm restart

This will install the extension (this works on PHP 5.5.3).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.