0

So from everything I have read, with firebase-tools installed globally, my Windows command prompt open at the folder containing my project, a working firebase.json file (working in that firebase deploy works fine) I should be able to run the following command to overwrite the entire contents of my firebase database:

firebase database:set / database.json

However with database.json I get the following error:

Error: HTTP Error: 400, Invalid data; couldn't parse JSON object, array, or value.

database.json contains the following:

{
  "catalogue": {
    "csi": {
      "descriptionRoute": "csi",
      "fileName": "ctk%20Currency%20Strength%20Indicator.algo",
      "id": 1,
      "imageUrl": "/images/csi.png",
      "isFeatured": true,
      "name": "Currency Strength Indicator",
      "shortDescription": "Plots the relative strength of 8 major currencies as a line chart",
      "type": "indicator"
    },
    "csh": {
      "descriptionRoute": "csh",
      "fileName": "ctk%20Currency%20Strength%20Heatmap.algo",
      "id": 2,
      "imageUrl": "/images/csh.png",
      "isFeatured": true,
      "name": "Currency Strength Heatmap",
      "shortDescription": "Plots the relative strength of 8 major currencies as a heatmap",
      "type": "indicator"
    },
    "ffc": {
      "descriptionRoute": "ffc",
      "fileName": "ctk%20FF%20Calendar.algo",
      "id": 3,
      "imageUrl": "/images/ffc.png",
      "isFeatured": true,
      "name": "Forex Factory Calendar",
      "shortDescription": "Lists upcoming events from the Forex Factory RSS feed",
      "type": "indicator"
    },
    "atrsl": {
      "descriptionRoute": "atrsl",
      "fileName": "ctk%20ATR%20Stop%20Loss%20Indicator.algo",
      "id": 4,
      "imageUrl": "/images/atrsl.png",
      "isFeatured": false,
      "name": "ATR Stop Loss Indicator",
      "shortDescription": "Displays ATR and stop loss values based on your requirements.",
      "type": "indicator"
    },
    "ha": {
      "descriptionRoute": "ha",
      "fileName": "ctk%20Heken%20Ashi.algo",
      "id": 5,
      "imageUrl": "/images/ha.png",
      "isFeatured": false,
      "name": "Heiken Ashi",
      "shortDescription": "Paints Heiken Ashi candles on the host chart.",
      "type": "indicator"
    },
    "hama": {
      "descriptionRoute": "hama",
      "fileName": "ctk%20Heken%20Ashi%20Moving%20Average.algo",
      "id": 6,
      "imageUrl": "/images/hama.png",
      "isFeatured": false,
      "name": "Heiken Ashi Moving Average",
      "shortDescription": "Paints Heiken Ashi Moving Average on the host chart.",
      "type": "indicator"
    },
    "psl": {
      "descriptionRoute": "psl",
      "fileName": "ctk%20Psych%20Levels%20.algo",
      "id": 7,
      "imageUrl": "/images/psl.png",
      "isFeatured": false,
      "name": "Psych Levels",
      "shortDescription": "Draws lines at psychological levels that often form string Support and Resistance",
      "type": "indicator"
    }
  }
}

I can't see anything wrong with this, everything I googled suggested it was fine, but the error was all I could get.

So I ran

firebase database:get / > database2.json

with the following result:

{
  "catalogue": [
    null,
    {
      "descriptionRoute": "csi",
      "fileName": "ctk%20Currency%20Strength%20Indicator.algo",
      "id": 1,
      "imageUrl": "/images/csi.png",
      "isFeatured": true,
      "name": "Currency Strength Indicator",
      "shortDescription": "Plots the relative strength of 8 major currencies as a line chart",
      "type": "indicator"
    },
    {
      "descriptionRoute": "csh",
      "fileName": "ctk%20Currency%20Strength%20Heatmap.algo",
      "id": 2,
      "imageUrl": "/images/csh.png",
      "isFeatured": true,
      "name": "Currency Strength Heatmap",
      "shortDescription": "Plots the relative strength of 8 major currencies as a heatmap",
      "type": "indicator"
    },
    {
      "descriptionRoute": "ffc",
      "fileName": "ctk%20FF%20Calendar.algo",
      "id": 3,
      "imageUrl": "/images/ffc.png",
      "isFeatured": true,
      "name": "Forex Factory Calendar",
      "shortDescription": "Lists upcoming events from the Forex Factory RSS feed",
      "type": "indicator"
    },
    {
      "descriptionRoute": "atrsl",
      "fileName": "ctk%20ATR%20Stop%20Loss%20Indicator.algo",
      "id": 4,
      "imageUrl": "/images/atrsl.png",
      "isFeatured": false,
      "name": "ATR Stop Loss Indicator",
      "shortDescription": "Displays ATR and stop loss values based on your requirements.",
      "type": "indicator"
    }
  ]
}

Then immdiately ran

firebase database:set / database2.json

And got the same error. I am stumped, if the format of the downloaded data can't be uploaded what format can do I need?

Mike Hanson
  • 266
  • 1
  • 8
  • This isn't much help, but I'll share that I was able to copy your JSON data and successfully upload it using the command you posted. I used `firebase-tools` version 3.9.0 (firebase -V) on a Windows system. – Bob Snyder May 20 '17 at 14:31
  • Thanks for trying Bob. I ran firebase -V and got 3.9.0 must be something strange about the file – Mike Hanson May 20 '17 at 16:33
  • Yes, I would guess it has something to do with character set or some other non-visible property of the file, although it's odd that the downloaded file failed also. – Bob Snyder May 20 '17 at 16:42

1 Answers1

2

I solved the problem and as Bob Snyder hinted the problem was the encoding of the file.

I created the file originally from the JSON file template in Visual Studio 2017. To check the encoding I opened it in NotePad++ and it showed the Encoding as UTF-8-BOM. I changed the Encoding to UTF-8 in NP++ and ran the original command:

firebase database:set / database.json

It worked first time and my database was overwritten.

So for anyone else that comes across this problem, make sure the Encoding of your JSON file is UTF-8.

Mike Hanson
  • 266
  • 1
  • 8