Firebase using floating point number as key

I realized that I get a 400 HTTP Bad Request from the server when I click on some JSON data in the Firebase storage, whose keys are floating point numbers. Here is the answer I received:

{"error" : "Invalid data; couldn't parse JSON object, array, or value. Perhaps you're using invalid characters in your key names."} 

I sent the following data:

 '[{"36.5": "4050952597550"}, {"41.5": "4050952597628"}]' 

I believe this is a perfectly valid JSON string in Python, because I don't get errors when encoding / decoding.

 import json v = [{u'36.5': u'4050952597550'}, {u'41.5': u'4050952597628'}] print v == json.loads(json.dumps(v)) True 

Is this some kind of mistake or am I missing something?

+2
source share
1 answer

This is valid JSON, but it is not valid Firebase. It does not seem to be like periods. If you really need to use floats for your property names (which sounds doubtful), you can try replacing periods with other characters, such as underscores or commas.

Discontinued from Linking in the Firebase documentation:

Character Set Limitations

Please note that the URLs used to create Firebase links can contain any unicode characters except:

  • . (Period)
  • $ (dollar sign)
  • [(left square bracket)
  • ] (right square bracket)
  • # (hash or pound sign)
  • /(slash)

and ASCII control characters 0-31 and 127.

You can check for the presence of these characters with this regular expression:

 /[\[\].#$\/\u0000-\u001F\u007F]/ 
+7
source

Source: https://habr.com/ru/post/1261267/


All Articles