Firebase - Invalid JSON data or key values. Key values can’t contain $ # [ ] / or

…衆ロ難τιáo~ 提交于 2020-06-07 21:11:58

问题


I'm trying to import my JSON file into my Firebase but it keeps giving me this error. I don't know why this JSON file isn't allowed to be imported into since JSONLint says it's a valid JSON file.

Here's the file:

{
  "Featured" : {
      "artist" : "james turell",
      "artistEPK" : "artistsownepk.pdf",
      "author" : "john queue author",
      "date" : "7/28/2016",
      "fullScreenImg" : "https://firebasestorage.googleapis.com/v0/b/wallplay-a8440.appspot.com/o/Screen%20Shot%202016-06-08%20at%2012.00.06%20PM.png?alt=media&token=1df5d60d-808c-48bb-a591-e005f82e4687",
      "linksToMedia" : [ "www.wallplay.com/project-name/james-t/press.html" ],
      "linksToPress" : [ "" ],
      "location" : "10 Main Street",
      "mainImg" : "https://firebasestorage.googleapis.com/v0/b/wallplay-a8440.appspot.com/o/Screen%20Shot%202016-06-08%20at%2012.00.06%20PM.png?alt=media&token=1df5d60d-808c-48bb-a591-e005f82e4687",
      "pressImgs" : [ "https://firebasestorage.googleapis.com/v0/b/wallplay-a8440.appspot.com/o/Screen%20Shot%202016-06-08%20at%2012.00.06%20PM.png?alt=media&token=1df5d60d-808c-48bb-a591-e005f82e4687", "https://firebasestorage.googleapis.com/v0/b/wallplay-a8440.appspot.com/o/Screen%20Shot%202016-06-08%20at%2012.00.06%20PM.png?alt=media&token=1df5d60d-808c-48bb-a591-e005f82e4687", "https://firebasestorage.googleapis.com/v0/b/wallplay-a8440.appspot.com/o/Screen%20Shot%202016-06-08%20at%2012.00.06%20PM.png?alt=media&token=1df5d60d-808c-48bb-a591-e005f82e4687" ],
      "pressRelease" : "projectpressrelease.pdf",
      "projectImgs" : [ "https://firebasestorage.googleapis.com/v0/b/wallplay-a8440.appspot.com/o/Screen%20Shot%202016-06-08%20at%2012.00.06%20PM.png?alt=media&token=1df5d60d-808c-48bb-a591-e005f82e4687", "https://firebasestorage.googleapis.com/v0/b/wallplay-a8440.appspot.com/o/Screen%20Shot%202016-06-08%20at%2012.00.06%20PM.png?alt=media&token=1df5d60d-808c-48bb-a591-e005f82e4687", "https://firebasestorage.googleapis.com/v0/b/wallplay-a8440.appspot.com/o/Screen%20Shot%202016-06-08%20at%2012.00.06%20PM.png?alt=media&token=1df5d60d-808c-48bb-a591-e005f82e4687" ],
      "projectSubheader" : "subheader of project",
      "projectTitle" : "title of project",
      "projectURL" : "",
      "soundFile" : [ ],
      "text" : "here there would be a text for james turell",
      "videoURL" : ""
    },
  "Future" : {

  },
  "Past" : {

  },
  "Present" : {

  }
}

the issue happens when importing json using the web interface


回答1:


I just spent some time on this and found the issue for me (and likely for many others) when getting this error message. It looks like firebase can only import files with UTF-8 encoding (no BOM)

I found it strange, as I couldn't re-import the content I had just exported.

I tried all UTF versions 8, 16 with LE and BE with and without BOM, only UTF-8 works

I wish firebase did not have this utterly misleading error message




回答2:


Two things that might help someone else save a couple of hours of head scratching:

1) Empty strings are valid JSON keys, they're NOT valid Firebase keys.

2) While the web tool error message is horrible, the command-line tool actually provides useful information like, say, a line number (nice when you have a 300K+ line file)

E.g.

firebase --project database:set / import.json

to overwrite everything from the root




回答3:


This happened to me, and had a totally different cause: I had Firebase functions that triggered when data is added to certain collections. The GUI tool gave me the unhelpful error the OP got. But running with the CLI, I got:

Error: HTTP Error: 400, This request would cause too many functions to be triggered.

So, the error ended up really saving my hide since running a function for each of the few hundred nodes I was importing would have been disastrous.

To solve the issue, I deployed my app code with the functions commented out and then was able to use the GUI to import my data. Once my data was in, I un-commented out the functions and deployed again.




回答4:


My filename was "something-somethingelse", ie it had a '-' character in the filename. Changing it to 'something.json' solved the problem

So, don't have any special characters in your filenames.




回答5:


The JSON you posted is valid for Firebase, so the issue is not with this JSON. It must be somewhere else in your application.




回答6:


if you created triggered function a lot of. You have to remove triggered functions. Next try again. That way works for me.




回答7:


I just found one more reason when Firebase throws this error:

This was the data firebase refused to upload:

 {
            "S. No.": 2,
            "University Name": "Acharya Nagarjuna University, Guntur (Id: U-0003)",
            "College Name": "Abhinav Institute of Management & Technology (Id: C-39450)",
            "College Type": "Affiliated College",
            "State Name": "Andhra Pradesh",
            "District Name": "Prakasam"
          } 

I thought of changing the key name of "S. No." and it worked.

{
            "S": 2,
            "University Name": "Acharya Nagarjuna University, Guntur (Id: U-0003)",
            "College Name": "Abhinav Institute of Management & Technology (Id: C-39450)",
            "College Type": "Affiliated College",
            "State Name": "Andhra Pradesh",
            "District Name": "Prakasam"
          } 

The Firebase was accepting the later format (I believe the problem was with .(dot) followed by space.) I hope this helps!!!




回答8:


I have a similar problem with JSON containing huge data. I solved this problem by using firebase import tool. It has options for imports to specific nodes etc.



来源:https://stackoverflow.com/questions/38668477/firebase-invalid-json-data-or-key-values-key-values-can-t-contain-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!