WordPress uses JSON (JavaScript Object Notation) to store and transfer data from the server to the web page, which can end in errors. JSON is particularly easy to understand for us (it’s “human-readable” instead of “machine-readable”) making it beginner-friendly, much like HTML. Both are used across WordPress websites, and though some users mix them up, JSON is a text-based format with data structured in JavaScript object notation while HTML is a markup language with defined rules. However, that knowledge rarely plays a part if the problem stems from failed data transport. Thus, let’s dive into how to fix invalid JSON error in WordPress.
Why do I get the “Invalid JSON error” in WordPress?
The cause of the JSON error is simple in theory. WordPress, the CMS (Content Management System) requested some form of data from the web hosting server while you were doing something, such as editing a page or post in Block Editor. Unfortunately, the response either failed to arrive or was in a different, unexpected format. Consequently, you saw the “The response is not a valid JSON response.” error. It may have a better explanation such as the one we had, that also stated “Updating failed.” Therefore, you must re-establish data transport using JavaScript in a JSON format to resolve the issue.
1. Check WordPress Site Health and use WP Debug
We understand many users feel uncomfortable looking through logs if they can try one solution after another to see what sticks. However, you may save time by checking the Site Health page by going to the left sidebar in WordPress admin, then Tools → Site Health. See if you notice something off about the critical components of your site.
For instance, you may see a problem stating “The REST API encountered an unexpected result”. Click to expand it, and it will hopefully provide an error code with the name of the theme, plugin, or service. If you do not, it may be a good idea to start debugging in WordPress. You can also use the latter as the last resort.
2. Solve an HTTP/HTTPS misconfiguration
A frequent source of this error is buying or renewing an SSL certificate or having inconsistency between HTTP and HTTPS in WordPress Settings. To check and solve the situation:
- Open the left sidebar of the WordPress Admin dashboard.
- Go to Settings → General.
- Under General Settings, find two lines under WordPress Address (URL) and Site Address (URL) and ensure they match. To clarify, they should both start with HTTP or HTTPS (we suggest switching to the latter as soon as possible) and either have/don’t have “www” depending on your domain.
In some cases, the two entries are different. However, that’s only when you assign WordPress to one directory and the website to another. You or your web hosting would know if this was the case.
3. Fix the invalid JSON error in WordPress by resetting or changing the WordPress permalink structure
If the error persists, there’s a chance that the structure of permalinks is troublesome. While changing it on a live website can be devastating for your SEO (Search Engine Optimization), you can undoubtedly refresh it and see if the JSON error shows up. Like in the method above, go to Settings. Then:
- This time select the Permalinks page. Take note of the currently applied permalink setting under “Common Settings”.
- Select any other setting but the current one before clicking Save Changes.
- After the changes are confirmed, choose the original permalink setting, then pick Save Changes once again.
- This refreshed permalink configuration. You can now go back to the post or page and see whether this was a fix to the JSON error for WordPress.
4. Generate a fresh WordPress .htaccess file to fix the error with invalid JSON
Data transport is closely related to permissions and the .htaccess file controls it, alongside permalinks and other SEO-friendly information. WordPress usually regenerates it automatically, but there’s a chance it wasn’t updated or was incorrectly set up. Thus, even if permalinks are correct, you may experience JSON-related problems. You now have three options:
- Find the .htaccess file in the root folder (which could be called public_html). Download it for safekeeping, then delete it.
- Rename the .htaccess file to something similar to old-htaccess.
- Open the .htaccess file, erase everything inside, and replace it with the default .htacces file.
5. Investigate a theme conflict in WordPress
Though WordPress itself is responsible for the post and page editing, a lot of themes alter the requests or come equipped with custom page editors. Then there’s the issue of incompatibility—whether you forgot to update the theme or the WordPress version itself. Before you make radical changes, it makes sense to temporarily disable your active WordPress theme like this:
- Since you still have access, visit the WordPress Admin section.
- Select Appearance.
- Go to Themes.
- Click the currently enabled theme.
- Select Deactivate.
- A default WordPress theme will be activated in its place. If the issue is solved, it likely means that your currently active plugins or WordPress itself are conflicting.
6. Disable certain or all WordPress plugins
This solution is similar to the one above, except that some plugins, instead of the themes, can be the culprit. While we suggest going through the entire list one by one, deactivating, and checking whether the error is gone in WordPress, you could start with firewall and security plugins, and those that deal with posts or pages in some way. If you want a quick solution, you can also turn off all plugins at once to see whether one was the root of the problem in the first place. There are two ways to deactivate WordPress plugins:
- Go to Plugins → All Plugins in WordPress Admin. Click on Deactivate underneath the plugin name one by one.
- Access your WordPress website via FTP. Go to root/wp-content/plugins/ and rename the plugins folder to plugins-old. Check your website for changes, and if the message is gone, go through plugins one at a time.
7. Use Classic Editor or disable JSON REST API temporarily
JSON is pivotal to the functionality of modern WordPress websites and Block Editor uses it extensively. However, in a pinch, you can try turning off the JSON REST API in WordPress. Make sure to have a site backup ready and revert the changes if the site breaks. Alternatively, you can stick to Classic Editor for publishing posts and pages for a time. While Classic Editor uses JSON, its application is drastically lower than in Gutenberg Editor.