1

I am using firebase realtime database, and when I try and upload a json object that has an array as a value, it gets converted. Example: What I upload:

{
"obj": [var1,var2,var3]
}

Firebase turns that into:

{
"obj": {
   0: var1,
   1: var2,
   2: var3
   }
}

I have no idea why this happens and it really messes with my code. If there is a way to work around this that would be great.

0

1 Answer 1

1

That's the expected behavior: arrays are turned into nodes with sequential numerical keys when you store them in the database, and nodes with (mostly) sequential numerical keys are turned into arrays when you load them.

So if you load the obj back into your application, it should show up as an array again. If that is not happening, show the code that you use to store and load the data.

Also see: Best Practices: Arrays in Firebase.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.