Trying to fix the invalid JSON error in WordPress?
This error appears when editing WordPress posts or pages on your website. You may see a message saying ‘The response is not a valid JSON response’ and updating that page would fail.
In this tutorial, we will show you how to easily fix the invalid JSON error in WordPress. We’ll also talk about why this error occurs and how to avoid it in the future.
What causes ‘Not a Valid JSON Response’ Error in WordPress?
Failure to receive an expected response from the server causes the ‘Not a valid JSON response’ error in WordPress.
If for some reason, WordPress fails to get the response, or the response is not in JSON format, then you will see the ‘Not a valid JSON response’ error.
This error could appear for many reasons. However, the most likely cause of it to occur is incorrect URL settings in WordPress or broken permalinks.
Now, let’s see how to easily fix the invalid JSON error in WordPress.
Important: Please make a complete WordPress backup before making any big changes to your website. This lets you easily restore your website to the previous state.
1. Check WordPress URLs in Settings
Firstly, you need to ensure that your WordPress Address and Site Address settings are correct.
Simply, navigate to Settings » General page. From here, you need to review the WordPress Address (URL) and Site Address (URL) fields.
For most websites, this setting needs to have the same URL in both fields.
However, rarely, some users may have given WordPress its own directory and serve the website on a different address. In that case, they can have different URLs here.
However, if your Site Address is incorrect then that would trigger the invalid JSON error in WordPress.
If you made any changes to the settings, then remember to click on the Save Changes button to store your settings. You can now edit a blog post and see if adding any new blocks or saving that post triggers the ‘Not valid JSON response’ error.
If you are still seeing the error, then continue reading.
2. Fix WordPress Permalink Structure
WordPress includes SEO friendly URL structure that lets you use human-readable URLs for your posts and pages.
However, sometimes a user may mess up the permalinks settings. This would make it impossible for the WordPress editor to get a valid JSON response and cause the error to show up.
To fix this, you need to simply go to Settings » Permalinks page. From here, you need to carefully review the permalink options.
If you are unsure whether you are using the right settings, then simply select one of the default formats available.
Next, go ahead and click on the Save Changes button to store your settings.
You can now try editing a blog post or page to see if the error has disappeared. If it hasn’t, then you can try this next step.
3. Regenerate WordPress .htaccess File
The .htaccess file in WordPress is used as a configuration file to manage SEO-friendly URLs (permalinks).
Normally, WordPress can automatically regenerate and update it. You can also trigger that update by simply clicking on the Save Changes button at the bottom of Settings » Permalinks page.
However, sometimes it may not get updated or has incorrect settings. This would affect your WordPress permalinks and may also cause an invalid JSON response error.
To fix this, you need to connect to your website using an FTP client or the file manager app in your WordPress hosting account dashboard.
After connected, you need to locate the .htaccess file in the root folder of your website and download it as a backup to your computer.
Next, you need to edit the .htaccess file using FTP client or the file manager app.
When the file opens, you need to delete all the code inside it and replace it with the following code:
Remember to save your changes and upload the file back to your website.
You can now visit your website and edit and post or page to see if you can reproduce the invalid JSON response error.
If you are still seeing the error, then there are a few more steps you can do.
4. View The Rest API Debug Log
The invalid JSON response error would also mean that WordPress REST API on your website encountered an error.
The REST API is the set of techniques WordPress uses to communicate with the server as you work on your website.
You can see details of this error in the WordPress Site Health tool. Go to the Tools » Site Health page.
Now, you may see an issue labeled ‘The REST API encountered an unexpected result’.
Clicking on it will show you more details which may give you some clues about which plugin or third-party service may be causing the issue.
If this doesn’t have any clue, then you can move on to the next step.
5. Deactivate All WordPress Plugins
Occasionally, WordPress plugins may conflict with each other or the WordPress core. This could result in unexpected behavior and could be a potential reason for the invalid JSON error.
Simply navigate 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 the Apply button to continue.
WordPress will then deactivate all your installed plugins.
You can now try again to reproduce the error. If the error disappears, then this means one of the plugins installed on your website was causing it.
To figure out which plugin, you need to activate them one by one and then try to reproduce the error. Repeat this until you find the culprit.
Next, you can reach out to the plugin author for support or find an alternative plugin.
6. Temporarily Switch to the Classic Editor
If all the above steps fail, then you can temporarily switch to the Classic Editor for WordPress.
This older version of WordPress editor uses a simpler text editor and doesn’t rely heavily on REST API to get JSON response.
To use it, you need to install and activate the Classic Editor plugin.
The plugin works out of the box, and it will disable the Gutenberg editor upon activation.
You can now go working on your website and get back to the troubleshooting later.
7. Further Troubleshooting
Many things can block WordPress REST API or make it return an invalid JSON response. We have addressed the most likely culprits above, but if that didn’t fix it for you then here are a few more steps that you can try.
Switching to a Default WordPress Theme
Sometimes a conflict between your WordPress theme and a plugin or the WordPress core may result in unexpected behavior.
You can test this, by simply switching to a default WordPress theme like TwentyTwentyOne or Twenty-Twenty.
Temporarily Turn off Website Application Firewall
If you are using a WordPress firewall like Sucuri, Cloudflare, or a plugin, then it is possible that they can sometimes block legitimate requests too.
The simplest way to figure this out is by temporarily disabling your WordPress firewall plugin or service.
Some application-level WordPress firewalls can be disabled by just deactivating the plugin. For DNS level firewalls like Sucuri and Cloudflare, you can disable them from your account dashboard.
Turn on Debugging in WordPress
WordPress comes with a built-in feature that lets you 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:
Then, WordPress will keep a log of all errors in a debug.log file located inside /wp-content/ folder. You can access this file by using an FTP client.
The error log may provide you a clue about what may be causing the invalid JSON error on your website.
Seek Expert Help
Lastly, if all else fails, then this could be due to a misconfiguration on your WordPress hosting server. Most reliable WordPress hosting companies are able to help users with common WordPress issues like that.
Simply reach out to them via live chat or support ticket and they may be able to help you fix it.
We hope this article has helped you learn how to fix the invalid JSON error in WordPress. Let us know which method worked for you in the comments below.