WordPress Beginner’s Guide
Are you trying to fix an invalid JSON error in WordPress?
This error appears when editing a WordPress post or page on your site. You’ll see a message saying ‘The response is not a valid JSON response’ and updating that page will fail.
In this article, we will show you how to easily fix invalid JSON error in WordPress. We will also talk about why this error occurs and how to avoid it in the future.
What causes the ‘Not a Valid JSON Response’ error in WordPress?
Failure to receive expected response from server causing ‘Not a valid JSON response’ error in WordPress.
If for some reason, WordPress fails to get a response, or the response is not in JSON format, you will see a ‘Not a valid JSON response’ error.
This error can arise for several reasons. However, the most likely cause is incorrect URL settings in WordPress or a broken permalink.
Having said that, let’s take a look at how to easily fix invalid JSON error in WordPress.
Important: Please make a complete WordPress backup before making any major changes to your website development. This allows you to easily restore your website to its previous state.
1. Check the WordPress URL in Settings
First, you need to make sure that your WordPress Address and Site Address settings are correct.
Simply, go to Settings »General page. From here, you need to review the WordPress Address (URL) and Site Address (URL) fields.
For most websites, this setting should have the same URL in both fields.
However, rarely, some users may provide their own WordPress directory and serve the website at a different address. If so, they can have a different URL here.
However, if your Site Address is wrong then it will trigger an invalid JSON error in WordPress.
If you make changes to the settings, don’t forget to click the Save Changes button to store your settings. You can now edit the blog post and see if adding a new block or saving the post triggered the ‘Invalid JSON response’ error.
If you still see the error, continue reading.
2. Fix WordPress Permalink Structure
WordPress comes with an SEO friendly URL structure that allows you to use human readable URLs for your posts and pages.
However, sometimes users might mess up the permalink settings. This will make it impossible for the WordPress editor to get a valid JSON response and cause the error to appear.
To fix this, you only need to visit the Settings »Permanent link page. From here, you need to carefully review the permalink options.
If you are not sure whether you are using the correct settings then simply select one of the available default formats.
After that, go ahead and click the Save Changes button to store your settings.
Now you can try editing the blog post or page to see if the error has gone away. If not, you can try this next step.
3. Regenerating WordPress .htaccess Files
The .htaccess file in WordPress is used as a configuration file for managing SEO-friendly URLs (permalinks).
Usually, WordPress can regenerate and update it automatically. You can also trigger those updates by simply clicking the Save Changes button at the bottom of the Settings »Permanent Link page.
However, sometimes it might not update or have wrong settings. This will affect your WordPress permalink and can also cause an invalid JSON response error.
To fix this, you will need to connect to your website using an FTP client or a file manager application in your WordPress hosting account dashboard.
Once connected, you need to locate the .htaccess file in the root folder of your website and download it as a backup to your computer.
Tip: Can’t find the .htaccess file? Check out this quick article on how to find .htaccess files.
After that, you will need to edit the .htaccess file using an FTP client or file manager application.
Once the file opens, you need to delete all the code in it and replace it with the following code:
Don’t forget to save your changes and upload the file back to your website.
Now you can visit your website and edit and post or page to see if you can reproduce an invalid JSON response error.
If you still see the error, there are a few more steps you can take.
4. View the Rest API Debug Log
An invalid JSON response error also means that the WordPress REST API on your website has encountered an error.
The REST API is a collection of techniques that WordPress uses to communicate with the server while you are working on your website.
You can view the details for this error in the WordPress Site Health tool. Visit the Tools page »Site Health.
From here, you may see an issue labeled ‘REST API is having unexpected results’.
Clicking on it will reveal more details which might give you some clues as to which third-party plugin or service might be causing the problem.
If this doesn’t provide any instructions, you can move on to the next step.
5. Disable All WordPress Plugins
Sometimes, WordPress plugins may conflict with each other or with the WordPress core. This can result in unexpected behavior and could be a potential reason for invalid JSON errors.
Just go to the Plugins »Installed Plugins page. From here, select all your WordPress plugins and then select ‘Deactivate’ under the Bulk Actions drop-down menu. Now, click on the Apply button to continue.
WordPress will now deactivate all your installed plugins.
You can now try again to reproduce the error. If the error goes away, it means that one of the plugins installed on your website is causing it.
In order to find out which plugins, you need to activate them one by one and then try to reproduce the error. Repeat this until you find the culprit.
After that, you can contact the plugin creator for support or look for alternative plugins.
6. Temporarily switch to Classic Editor
If all the above steps fail, you can temporarily switch to Classic Editor for WordPress.
This older version of the WordPress editor uses a simpler text editor and relies less on the REST API to get JSON responses.
To use it, you need to install and activate the Classic Editor plugin. For more details, see our step by step guide on how to install a WordPress plugin.
The plugin works out of the box, and it will disable the Gutenberg editor upon activation.
You can now continue working on your website and return to troubleshooting later.
7. Further Troubleshooting
A number of things can block the WordPress REST API or make it return an invalid JSON response. We’ve covered the most likely causes above, but if that doesn’t fix it for you, here are a few more steps you can try.
Switch to the Default WordPress Theme
Sometimes a conflict between your WordPress theme and a WordPress plugin or core can result in unexpected behavior.
You can test it out, just by switching to a default WordPress theme like TwentyTwentyOne or Twenty-Twenty.
Temporarily Turn Off Website Application Firewall
If you use a WordPress firewall like Sucuri, Cloudflare, or a plugin, sometimes they can block legitimate requests too.
The easiest way to find out is to temporarily disable your WordPress firewall plugin or service.
Some application-level WordPress firewalls can be disabled by simply deactivating a plugin. For DNS level firewalls like Sucuri and Cloudflare, you can disable them from your account dashboard.
Enable Debugging in WordPress
WordPress comes with a built-in feature that allows you to keep a log of errors. However, it is not enabled by default.
To turn it on, you need to add the following code to your wp-config.php file:
After that, WordPress will keep a log of all errors in the debug.log file which is located in / wp-content / folder. You can access this file by using an FTP client.
The error log can provide you with clues as to what might be causing an invalid JSON error on your website. For more details, see our guide on setting up WordPress error logs and using them to debug errors.
Seek Expert Help
Lastly, if all else fails, it could be due to a misconfiguration of your WordPress hosting server. Most reliable WordPress hosting companies can help users with such common WordPress problems.
Just contact them via live chat or a support ticket and they might be able to help you fix it.
We hope this article helped you learn how to fix invalid JSON error in WordPress. Let us know which solution worked for you in the comments below.
You may also want to see our complete handbook on the most common WordPress errors and how to fix them.
If you liked this article, please subscribe to our YouTube channel for WordPress video tutorials. You can also find us on Twitter and Facebook.