Format a GeoJSON Feature Collection
GeoJSON is the RFC 7946-standardized format for encoding geographic data and is used by virtually every modern web mapping library including Leaflet, Mapbox GL, Google Maps, and Deck.gl, as well as spatial databases like PostGIS. Understanding its structure is essential for anyone building mapping features, processing location data from APIs, or storing geographic information in a database. This example shows a FeatureCollection containing two features: a Point marking the Empire State Building and a Polygon representing a bounding area of Manhattan. The FeatureCollection is the most common top-level GeoJSON type you'll encounter because it allows you to group multiple features into a single document that mapping libraries can render in one call. The most common and hardest-to-debug error in GeoJSON is the coordinate order. GeoJSON always uses [longitude, latitude] ordering — the opposite of what most people intuitively write and the opposite of what GPS devices report (which give latitude first). A map that renders your points in the ocean instead of on land almost certainly has swapped coordinates. Formatting the GeoJSON first makes it easy to cross-check coordinate values against known reference points. Key parts explained: the type field at the Feature level must be exactly "Feature" (capital F). Each Feature's geometry has a type (Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, or GeometryCollection) and a coordinates array whose structure varies by type. The properties object is a free-form key-value store for any metadata you want to attach to the feature. Polygon coordinates have an extra layer of nesting compared to LineString: coordinates is an array of rings, where the first ring is the exterior boundary and subsequent rings are holes. Each ring must close itself by repeating the first coordinate as the last. Real-world scenario: you're importing store locations from a CSV, converting them to GeoJSON, and the map shows them all in the wrong country — formatting the output and checking the first few coordinates against Google Maps confirms the longitude/latitude swap. To customise: replace the coordinates with your own locations using the format [longitude, latitude] and add any metadata you need to the properties objects.
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": { "type": "Point", "coordinates": [-73.9857, 40.7484] },
"properties": { "name": "Empire State Building" }
},
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [[[-74.0, 40.7], [-73.9, 40.7], [-73.9, 40.8], [-74.0, 40.8], [-74.0, 40.7]]]
},
"properties": { "name": "Manhattan Area" }
}
]
}FAQ
- What coordinate order does GeoJSON use?
- GeoJSON always uses [longitude, latitude] order — the opposite of many mapping APIs. This is a frequent source of bugs where points appear in the wrong hemisphere.
- How do I close a GeoJSON polygon?
- The last coordinate in a Polygon ring must be identical to the first coordinate. This closes the ring; omitting it causes rendering issues in some parsers.
- Can GeoJSON store custom properties?
- Yes. Each Feature has a properties object where you can store any key-value data you want associated with that geometry.
Related Examples
REST APIs return compact, minified JSON to save bandwidth, but that makes the re...
Explore Deeply Nested JSONDeeply nested JSON is one of the most common sources of confusion when working w...
Convert JSON Array to CSVA JSON array of objects where each object has the same keys is the standard form...