Error: Unable to parse JSON: SyntaxError: Unexpected token } in JSON at position 540

Viewed 1011

I'm trying to deploy a project with firebase init. When I get to the part that asks me this: "What file should be used for Realtime Database Security Rules? database.rules.json", I press enter and an error appears:

Error: Unable to parse JSON: SyntaxError: Unexpected token } in JSON at position 540

What should I do? Help pls.

1 Answers

Using the --debug argument I've found out that if there isn't a database.rules.json file in the init directory, it will automatically copy what is online in the project. But here's the problem: If the database hast been initialized yet, it will return invalid json (since the rules haven't been setup yet).

So here's how to fix:

  • Create your own database.rules.json file in your project directory and configure it with valid json.
{
    "rules": {
        ".read": true,
        ".write": false
    }
}
  • When you run firebase init and get to the part where it asks you What file should be used for Realtime Database Security Rules? use the already created file (so usually just 'database.rules.json').
  • If you pointed to the correct file it will ask you File database.rules.json already exists. Do you want to overwrite it with the Realtime Database Security Rules for insektenhotel-default-rtdb f rom the Firebase console? (This is automatically yes if the files doesn't exist, causing the problem). Say No.

It should work now.

Related