Converting a GeoJSON Object to a Javascript Array

I need to convert GeoJSON output from the server to a Javascript array; I did some searches, and they were for "regular" JSON outputs, not GeoJSON. Here is the output from the server:

{"type":"FeatureCollection","features":[{"type":"Feature","property":"blah"}, {"type":"Feature","property":"blah2"}]}

And here is what I need (note: no quote from the "features" variable is required):

features = [{"type":"Feature","property":"blah"}, {"type":"Feature","property":"blah2"}]}

I think I need to find the "features" property and then scroll through its objects? Thank!

+4
source share
1 answer

The GeoJSON object is still a JSON object (this is the first thing their documentation says).

http://geojson.org/geojson-spec.html

PROPERTY GeoJSON, , , javascript .

var geoObject = JSON.parse(geoJSONObject);
var features = [];

features = geoObject.features;
+3

All Articles