Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase JSON data consisting arrays

This is my firebase database. enter image description here When I export the JSON of this database it gives me the following JSON data:-

{
"app1": {
    "app-icon": "some-icon",
    "app-name": "AmazingApp",
    "feature-id": 1,
    "image-list": {
        "image1": {
            "image-display-time": 20,
            "image-name": "Name",
            "image-sequence": 1,
            "music-file": "some mp3 file"
        },
        "image2": {
            "image-display-time": 25,
            "image-name": "Name",
            "image-sequence": 2,
            "music-file": "some mp3 file"
          }
        },
        "image-time-enabled": false
   }
}

Here image-list is a array but from what I know firebase does not support arrays, hence there are no [ ] which denotes a array. So if I give this JSON data to any third party to consume they are not able to consume this data since they cannot loop over the children of the node image-list as it is technically not an array(though it is meant to be a array).

How do I get to work with such a JSON data?

NOTE : The third party uses javascript and won't be accessing the firebase database directly instead they would just consume json coming from a plain text.

like image 839
Parag Kadam Avatar asked Apr 16 '26 10:04

Parag Kadam


1 Answers

They can use the for-in loop like below to get the objects.

for (var key in image-list) {
  if (image-list.hasOwnProperty(key)) {
    console.log(key + " -> " + JSON.stringify(image-list[key]));
  }
}
like image 131
Vikram Palakurthi Avatar answered Apr 18 '26 22:04

Vikram Palakurthi