3

I need to comment out some lines from the firebase.json file:

Example:

"rewrites": [
      // {
      //  "source": "/blog/*", 
      //  "function": "handleBlog"
      // },
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]

In this case, I want to disable that rewrite temporarily but I do not want to delete the code.

The fact is that JSON files do not allow comments and I get an error from VSCode telling me that.

But if I set the Language Mode to JSON with Comments, the errors from VSCode are gone.

enter image description here

But is it safe to do? How does Firebase handle a firebase.json file with comments?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
cbdeveloper
  • 27,898
  • 37
  • 155
  • 336

3 Answers3

3

JSON format does not support comments. Comments of the form //… or /*…*/ are not allowed in JSON More info can be found here.

As far as firebase goes, I am not familiar with it, but if set Language Mode to JSON with Comments in VSCode, you will get JSONC file format, not JSON. JSONC is used specifically in VSCode:

In addition to the default JSON mode following the JSON specification, VS Code also has a JSON with Comments (jsonc) mode. This mode is used for the VS Code configuration files such as settings.json, tasks.json, or launch.json.

Matt
  • 1,245
  • 2
  • 17
  • 32
3

I've had commented JSON in my one of my firebase.jsons for a while without issue.

{
    "hosting": {
        "headers": [
            /*{
              "source": "*.html",
              "headers": [
                {
                  "key": "Content-Security-Policy",
                  "value": "default-src 'self' ..."
                }
              ]
            },*/
        ]
    }
}
abraham
  • 46,583
  • 10
  • 100
  • 152
1

Firebase's documentation here use // for comments. I'd say it's safe to follow their approach.

I've also tested this format of commenting in .firebaserc. It works in there as well for me.

chjch
  • 901
  • 9
  • 13