WordPress Tutorials

How to Fix an Invalid JSON Error in WordPress

Unlike other errors, and invalid JSON error in WordPress is straightforward to understand and fix. For the unaware, this appears when WordPress can’t communicate with the web server while you work within the Block Editor. The server’s responses come in the JSON format, which explains the error.

Fixing the issue shouldn’t take more than a few minutes, and will be one of the following:

One of these will be the solution, although the hope is that you won’t need to look at all of them. We’re presenting the five solutions here from easiest to hardest, although that’s relative as you’ll likely have the skills you need to tackle each one in no time.

1. Carry Out Some Simple Steps to Diagnose the Error

Before you dig around in settings screens, you’ll want to ensure you aren’t the cause of the invalid JSON error in WordPress. However, create a full backup of your site first in case you need to reinstate your site later.

Once you have a backup in the bag, look to tick off all of the following ‘gotchas’:

  • Switch to a default theme, in case your primary one has a fault.
  • Turn off your Web Application Firewall (WAF), if you use one. It could be that you’ll disable your security plugin as a whole on a temporary basis.
  • Speaking of which, it’s a good idea to deactivate and reactive your plugins to see if one is the cause of the invalid JSON error in WordPress. This is a typical troubleshooting step within the platform, and can sometimes spotlight an issue with a rogue plugin.
  • Try using the Classic Editor, to see if you can still achieve what you need without seeing the error. However, you shouldn’t consider this a permanent fix, more scraping the rust off of a faulty engine.

If you don’t have WordPress’ debug mode active, you should also do this so you can try and catch the fault of the error. However, it’s likely going to be one of the below solutions, and they won’t take too long to resolve.

2. Check Your WordPress URLs

For the first method, you’ll want to log into WordPress and head to the Settings screen:

On the General tab, check out the two fields that read WordPress Address (URL) and Site Address (URL). In the vast majority of cases, they will be the same as the domain name for your site:

You’ll likely know if your have WordPress under a different directory that would explain a clear difference here. However, a difference WordPress doesn’t understand will trigger the invalid JSON error.

It could be that those URLs use the wrong HTTP protocol: If you have a Secure Sockets Layer (SSL) certificate, each URL should use https://. Our advice is to check for spelling mistakes in each URL, and also check whether each ones uses the right protocol.

Once you make any fixes, save your changes and check for the error. If it still crops up, head to the next method.

While you’re in the Settings page, head to the Permalinks tab. There could be an issue under the hood with your permalink structure that could cause the invalid JSON error in WordPress.

The solution here is simple:

  • Choose a permalink type. Unless you use a Custom Structure, stick with the current option on this page.
  • Save your changes. This will ‘rest’ your permalink settings, and should rid you of the invalid JSON error in WordPress.

However, if you use a custom permalink structure, make sure there are no spelling mistakes or syntax errors with the tags you use:

Even one character out of place will cause the error, so look to fix anything you spot, save your changes, and check for further issues.

4. Take a Look at the Site Health Log for Clues

WordPress includes a handy screen to help you judge how ‘healthy’ your site is. The Site Health page is essentially a list of critical issues and recommended improvements to help with aspects of your site. For example, you can optimize performance, work on your Search Engine Optimization (SEO), and more:

If you encounter the invalid JSON error in WordPress, you may see another recommended improvement: “The REST API encountered an unexpected result”. This should give you some indication of where the JSON error lies, and from there you can investigate further.

However, if you don’t have much experience reading error logs like this, you might want to contact your host. This way, they can tell you what the issue pertains to, and whether it’s something on the server side.

5. Rebuild Your .htaccess File

The final method to solve the invalid JSON error in WordPress is the toughest, but still straightforward. Your .htaccess file is a set of configurations for Apache servers.

Unlike Nginx, Apache users can handle server configurations. As such, this could cause an invalid JSON error in WordPress.

The best approach here is to rebuild the .htaccess file itself, which is simple to do. In fact, you may have already done this when changing your permalink settings, as saving your changes here regenerates the .htaccess file.

However, you might want to create a clean file yourself from scratch, to be sure you don’t introduce an error or keep one around.

First, you’ll want to make a backup of your old .htaccess file. To do this, we recommend using Secure File Transfer Protocol (SFTP) to access your server and drag the .htaccess file to your local computer. Here’s what you’ll need:

Administrative access to your server, and the login credentials. You can often find these within your hosting control panel, or in an email from your host.

Your .htaccess file will be in the root of your site’s primary directory, and the process is to drag it out onto your computer (and set for hidden files to show):

From here, make a duplicate on your computer, clear out the contents, and add the following:

# BEGIN WordPress
 
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
 
# END WordPress

This is a default .htaccess file. Save it as .htaccess, then upload it to your server again. From here, check for the error.

Conclusion

The invalid JSON error in WordPress is simple to understand and fix, which is good if you need to continue working on your site in a hurry. Most of the solutions to this error relate to a configuration setting for your server, so you’ll poke around within WordPress’ settings screens to solve it.

In some cases, you’ll need to rebuild a .htaccess file from scratch, but even this is friction-free. However, if you still see the error on your site, it’s a good idea to contact your host for further advice. There could be something on the server that doesn’t play nicely with your site’s configuration that they will need to look into.

Do you suffer from the invalid JSON error in WordPress, and does one of our solutions help you? Let us know in the comments section below!

Tom Rankin

Tom Rankin is a quality content writer for WordPress, tech, and small businesses. When he's not putting fingers to keyboard, he can be found taking photographs, writing music, playing computer games, and talking in the third-person.

View Comments

  • Hi, I got issue, that is not fixable by the tutorial(s) found on net.

    There's extra '0' in json or other mess.

    Can you help me ?

Recent Posts

How to Start an Online Course Using WordPress and LearnDash

Trying to figure out how to start an online course so that you can share…

1 month ago

LearnDash Review 2024: The Best WordPress LMS Plugin?

Considering using LearnDash to create online course content with WordPress? LearnDash is a popular WordPress…

2 months ago

WordPress XML Files: What They Are and How to Open Them

WordPress XML files see a lot of use for me as a content creator, and…

2 months ago

6 Best WordPress LMS Plugins – Detailed Comparison & Review for 2024

If you’re looking for a way to deliver an online course, complete with all the…

2 months ago

The Top 8 SEO Tools And WordPress Plugins For Maximum Visibility (2024)

Search Engine Optimization (SEO) is crucial for any website that wants to maximize its traffic…

3 months ago

Kinsta Hosting Review 2024: Is This WordPress Host Worth the Investment?

Kinsta is a notable brand in the WordPress hosting space. The standout aspect of the…

4 months ago