drumttocs8
drumttocs8

Reputation: 21

Method to assign object IDs to imported JSON in Firebase

Firebase is organizing an imported JSON file in the following way:

Firebase database view

But the imported file (and exported file from Firebase) is organized this way:

 {
  "features" : [ {
    "geometry" : {
      "coordinates" : [ -77.347191, 36.269321 ],
      "type" : "Point"
    },
    "properties" : {
      "name" : "Branch Chapel",
      "osm_id" : "262661",
      "religion" : "christian"
    },
    "type" : "Feature"
  },
...

It appears that Firebase assigns an internal number to each object in the array of "features". This is nice, but it makes it hard to reference each object without knowing how Firebase is naming it- and I have 400k+ objects.

Is there a way to assign an id to each object to prevent Firebase from generating its own? Or is there a way to programmatically rename/reorganize the data after it's been imported? The optimal outcome would have the object named by its osm_id, rather than some arbitrary number Firebase assigns.

Any help is appreciated.

Upvotes: 2

Views: 1095

Answers (1)

atreeon
atreeon

Reputation: 24087

get rid of the square brackets and replace with squiggley brackets

this

{
    "flags": {
        "1": {
            "information": "blah",
        },
        "2": {
            "information": "It is great!",
        },
        "3": {
            "information": "Amazing!",
        }
    }
}

not this

[
    {
        "1": {
            "information": "blah",
        }
    },
    {
        "2": {
            "information": "It is great!",
        }
    },
    {
        "3": {
            "information": "Amazing!",
        }
    }
]

Upvotes: 2

Related Questions