composer.json does not contain valid json Laravel Error Message

Posted on

Another article specifying error message which is a Laravel Error Message as stated in the title of this article. The error generated is ‘composer.json does not contain valid json’. In this article, there will be a narration on the cause of the error, the background of how the error is being ignited as the main trigger and the last one is about how to solve the error.

It must be edited because there is some part of the file which is changed after executing the following command :

user@hostname:/var/www/html/laravel-project$ php artisan app:name Laravel-Testing
Application namespace set!
The compiled class file has been removed.
user@hostname:/var/www/html/laravel-project$ vim .env

The cause of error which is actually an indirect cause of directly editing a file named ‘composer.json’ located in the root folder of the laravel project directory. So, the content of composer.js is pointed out in the following location shown in the form of tree format :

user@hostname:/var/www/html/laravel-project$ tree -aL 1
.
├── app
├── artisan
├── bootstrap
├── composer.json
├── composer.lock
├── config
├── database
├── db
├── .env
├── .env.example
├── .gitattributes
├── .gitignore
├── gulpfile.js
├── logs
├── nbproject
├── package.json
├── phpunit.xml
├── public
├── readme.md
├── resources
├── routes
├── server.php
├── storage
├── temporary
├── tests
└── vendor

14 directories, 12 files
user@hostname:/var/www/html/laravel-project$

As shown in the above output generated from the ‘tree’ command execution, the composer.json file is located in the root folder of Laravel project. The error is actually caused from the entry or false editing and input of the file itself. Below is the content of the composer.json file which is being the target of the edit process :

  "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "Laravel-Testing\\": "app/"
        }
    },

It is changed and edited into the following content :

  "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
        //    "Laravel-Testing\\": "app/"
            "App\\": "app/"
        }
    },

Although the edit process is meant to solve the problem by editing or giving a remark sign of comment to the part which caused the problem and it is followed after that by the addition process through inserting a correct line of code, it becomes the background for triggering the error message. As shown in the title, the error is actually has something to do with composer.json which does not contain valid json. It is obvious since the json format content is disrupted with the comment to ruled out the error cause.

To solve it, just remove the snippet code which is becoming the part of the problem and add the actual snippet code chosen for it. So, the composer.json must be edited and it is shown as follows :

  "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },

Try to execute ‘composer dumpautoload -0’ and access the web-based application powered by Laravel framework..

 

One thought on “composer.json does not contain valid json Laravel Error Message

Leave a Reply