2

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
  • 499,950
  • 69
  • 739
  • 734
cbdeveloper
  • 21,907
  • 18
  • 110
  • 225

2 Answers2

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
  • 44,161
  • 9
  • 92
  • 140
2

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,156
  • 2
  • 17
  • 29