sgrove
sgrove

Reputation: 1199

Empty arrays dropped in POST request to Firebase

When trying to push a hashmap to a list using the Firebase REST API, any key:value pair that has an empty array as a value will be silently dropped, for example:

curl -X POST -d '{"name": "Persists", "words": ["what", "is", "this"], "toBeDropped": []}' "https://fbdev.firebaseio.com/channels/example.json?auth=sometoken

Results in a Firebase data structure:

{
 "random-id": {
    "name": "Persists",
    "words": ["what", "is", "this"]
  }
}

This is causing problems on our client, as they expect to toBeDropped to be [] and not null in this case.

Upvotes: 2

Views: 1708

Answers (1)

Andrew Lee
Andrew Lee

Reputation: 10195

This is actually the expected behavior for Firebase. Internally, Firebase treats arrays and objects as the same type (and only converts them to arrays on the clients if all of the key names are integers). Firebase also treats empty objects and null as the same type.

As a result, your empty array ends up being null.

Upvotes: 7

Related Questions