Reputation: 52173
I realized that I get 400 HTTP Bad Request from the server when pushing some JSON data into my Firebase storage whose keys are floating-point numbers. Here is the response I got:
{"error" : "Invalid data; couldn't parse JSON object, array, or value. Perhaps you're using invalid characters in your key names."}
The data I sent is as follows:
'[{"36.5": "4050952597550"}, {"41.5": "4050952597628"}]'
I believe it is perfectly a valid JSON string in Python because I get no errors while encoding/decoding it.
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 a bug or am I missing something?
Upvotes: 3
Views: 1217
Reputation: 23945
It's valid JSON, but it's not valid Firebase. It doesn't appear to like the periods. If you really have to use floats for your property names (which sounds questionable), you can try replacing the periods with other characters, like underscores or commas.
Taken from the Creating References page in Firebase's documentation:
Character Set Limitations
Note that URLs used to construct Firebase references may contain any unicode characters except:
and ASCII control characters 0-31 and 127.
You could check for the existence of these characters with this regular expression:
/[\[\].#$\/\u0000-\u001F\u007F]/
Upvotes: 9