3

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.

1 Answer 1

4

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]));
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

What does p refer to ? I suppose it is array image-list.
Yes p refer to the image-list.

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.