Hosting & Domaining Forum

Hosting Discussion => Web Hosting => Topic started by: rozepeter on Mar 01, 2023, 12:04 AM

Title: JSON doesn't work in my webhosting PHP
Post by: rozepeter on Mar 01, 2023, 12:04 AM
Hello, esteemed users of the forum.
I am facing an issue and I am hopeful that we can find a solution together.
The issue at hand is that the json_encode() and json_decode() functions are not functioning properly on my hosting.

Typically, when attempting to use these functions, an error occurs:

     Fatal error: Call to undefined function json_encode() in ***.php


Moreover, when employing the Code Igniter helper, a different error arises:

     Message: Undefined variable: json

It seems that both scenarios are related to the same problem, which leaves me puzzled and in need of assistance. Any ideas or suggestions would be greatly appreciated.
Title: Re: JSON doesn't work in my Hosting PHP
Post by: Priyanka on Mar 01, 2023, 01:02 AM
If feasible, it would be advantageous to upgrade PHP to either version 8.1 or 8.2. This upgrade should enable the proper functionality of the json_encode() and json_decode() functions.

Alternatively, if upgrading is not an option, it is necessary to investigate the presence of any undeclared variables within the CI framework or consider utilizing alternative implementations of these functions.
Title: Re: JSON doesn't work in my Hosting PHP
Post by: Optimitron on Mar 01, 2023, 02:12 AM
Contact the technical support of your hosting provider and request them to compile a complete version of PHP that includes the enabled JSON extension.

In dire circumstances where changing the host or PHP delivery is not possible, you can consider developing your own equivalents of the json_encode() and json_decode() functions. However, this should only be considered as a last resort.
Title: Re: JSON doesn't work in my Hosting PHP
Post by: Zora2012 on Mar 01, 2023, 02:44 AM
As an alternative solution (without having to meddle with the hosting provider), I suggest utilizing the Zend_Json_Encoder classes. Declare the functions json_encode() and json_decode() in the global scope, within which you can invoke Zend_Json_Encoder::encode()/decode() accordingly.

Admittedly, this approach may seem cumbersome; however, in the absence of any other viable options, it is worth a try. For further guidance, refer to framework.zend.com/manual/en/zend.json.basics.html
Title: Re: JSON doesn't work in my webhosting PHP
Post by: anilkh7058 on Jul 26, 2023, 12:41 AM
The same issue that I am facing. It will be helpful to me if someone gives solution on it.
Software Development Company (https://www.techmahajan.com/)
Title: Re: JSON doesn't work in my webhosting PHP
Post by: simonatkins on Jul 26, 2023, 11:28 AM
Hello! I'd be happy to help you with your issue regarding the json_encode() and json_decode() functions. The error you are encountering suggests that these functions are not enabled on your hosting server.

To resolve this, you can try the following:

1. Check PHP Version: Ensure that you are using a version of PHP that supports the JSON functions (usually PHP 5.2.0 or higher).

2. Enable JSON Extension: If the JSON extension is not enabled in your PHP configuration, you will need to enable it. This can typically be done by editing your php.ini file and uncommenting the line that enables the JSON extension. If you don't have access to the php.ini file, you can contact your hosting provider for assistance.

3. Restart Server: After making any changes to the PHP configuration, it's important to restart your web server to apply the changes.

Once you have made these changes and restarted your server, the json_encode() and json_decode() functions should work properly. If you continue to encounter issues, it may be helpful to provide more details about your hosting environment (such as the server software and version) so that others can assist you further.


some additional information.

If you have checked the PHP version and ensured that it supports JSON functions, but you are still encountering errors, here are a few more things you can try:

1. Verify Extension Loading: Confirm that the JSON extension is actually loaded in your PHP environment. You can create a PHP file with the following code to check it:

```php
<?php
phpinfo();
?>
```

When you run this file in your web browser, it will display a comprehensive PHP information page. Look for the JSON section to see if the extension is listed and enabled.

2. Check for Shared Hosting Limitations: If you are on shared hosting, there might be restrictions imposed by your hosting provider. In such cases, you may need to contact them and ask if JSON functions are allowed or if there are any steps you need to take to enable them.

3. Consult Hosting Support: Reach out to your hosting provider's support team and explain the issue you are facing. They should be able to investigate the problem and assist you further with resolving the JSON function errors.

It's worth noting that the CodeIgniter error message you mentioned (Undefined variable: json) does not seem directly related to the JSON functions. It might be a separate issue within your CodeIgniter application. You could try searching for that specific error message to find potential solutions or consult the CodeIgniter dоcumentation or community for assistance.
Title: Re: JSON doesn't work in my webhosting PHP
Post by: rickhaw on Oct 28, 2025, 01:31 AM
Check your php.ini for 'extension=json.so' or enable it via cPanel, if that's absent, escalate to your provider for a quick compile. For CodeIgniter, ensure the url_helper is loaded properly in your config/autoload.php; if $json is borked, it's a load error, not a core function fault.

Dive into error logs via debug mode, rewrite rules might be muddying serialize/unserialize alternatives. Toolkit: phpinfo() probe for loaded extensions, MVC sanity check, and consider cURL fallbacks if APIs are involved.
Title: Re: JSON doesn't work in my webhosting PHP
Post by: psychicrajsharma on Nov 07, 2025, 05:34 AM
JSON functions failing on my PHP webhost? Check PHP version (needs ≥5.2), enable json extension, verify headers (Content-Type: application/json), correct file permissions, inspect error logs, or contact host support.