How to fix "Config file is not valid JSON" in Ghost

Endrit Qerreti

Endrit Qerreti

In this tutorial you will learn how to fix the error code Config file is not valid JSON on your Ghost blog.

Why does this issue happen?

This issue happens when file config.production.json is not configured correctly or when the syntax is not correct.

To identify this issue when it happens and troubleshoot it follow the steps below.

1) Check if Ghost is Running

If the config.production.json file is not configured correctly Ghost instance won't be able to start, and if it was running while you got into this issue ghost would stop.

This could happen when you are editing the config json file and not check if your site is working or not after.

To avoid this from happening, it is always a good habit to save a copy of your config.production.json working configuration.

To check if Ghost instance is running, run the command below

ghost status

For example, since config.production.json's syntax was not correct, Ghost instance was not running

──────────────┬───────────────────┬─────────┬─────────┬─────┬──────┬─────────────────┐
│ Name         │ Location          │ Version │ Status  │ URL │ Port │ Process Manager │
├──────────────┼───────────────────┼─────────┼─────────┼─────┼──────┼─────────────────┤
│ owlhowto-com │ /var/www/owlhowto │ 5.39.0  │ stopped │ n/a │ n/a  │ n/a             

2) Run Ghost Doctor

Ghost doctor is another useful command that you can use to check for issues that your Ghost instance may be facing.

ghost doctor

In our case config.production.json has a syntax error, so when we run the ghost doctor command, we get the following errors "Validating config" which means "Config file is not valid JSON" as shown in the image below

3) Check Syntax on Config file

If you made changes to the config file and can't find what the issue is then you can use a json validator tool. This tool helps you check your json configuration for any possible syntax error.

The JSON Validator
JSONLint is the free online validator and json formatter tool for JSON, a lightweight data-interchange format. You can format json, validate json, with a quick and easy copy+paste.

Simply copy and paste your json code on the code box and click the validate button, if the json code has no syntax error the response will be "Valid JSON"

The content of the config.production.json looks like this

{
  "url": "http://owlhowto.com:10000",
  "server": {
    "port": 10000,
    "host": "0.0.0.0"
  },
  "database": {
    "client": "mysql",
    "connection": {
      "host": "owlhowto",
      "port": 3306,
      "user": "owlhowto",
      "password": "DATABASE_PASSWORD",
      "database": "DATABASE_NAME"
    }
  },
  "mail": {
    "transport": "Direct"
  },
  "logging": {
    "transports": [
      "stdout"
    ]
  },
  "paths": {
    "contentPath": "/var/www/owlhowto/content"
  }
}

And the example result showing the checked JSON was valid

In our case the error was being caused by a quote misplaced at the new line under database and not at the end of password.  

4) Restart Ghost

Once you validate the cofing.production.json file, proceed by restarting Ghost.

ghost restart

Restarting is needed after making changes on your Ghost production file.

Conclusion

In this tutorial you learned how to fix the issue "Config File is not valid JSON" in Ghost.