GeoJSON is the JSON format for maps. Leaflet, Mapbox, OpenLayers, PostGIS, QGIS and most GIS APIs read and write it. The whole spec is small, but a few rules trip everybody up.
The structure
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": { "type": "Point", "coordinates": [-122.4194, 37.7749] },
"properties": { "name": "Downtown Store" }
}
]
}
- FeatureCollection: the usual root, holding a
featuresarray. - Feature: one thing on the map, with a
geometryand apropertiesobject (your attributes, ornull). - geometry: the shape.
Geometry types
| Type | coordinates | Example use |
|---|---|---|
Point | [lon, lat] | a store |
LineString | [[lon, lat], …] | a route |
Polygon | [[[lon, lat], …]] (rings) | a delivery zone |
MultiPoint / MultiLineString / MultiPolygon | arrays of the above | islands, multi-part areas |
GeometryCollection | geometries: [...] | mixed shapes (use sparingly) |
Rule 1: longitude first
[-122.4194, 37.7749] is San Francisco. [37.7749, -122.4194] is somewhere in Antarctica. GeoJSON is x, y, which means longitude, latitude, even though most people say "lat, long".
Rule 2: close and wind your polygons
A Polygon is an array of linear rings. The first ring is the outer boundary and any others are holes.
- Each ring must be closed: the last position repeats the first.
- RFC 7946 says outer rings go counter-clockwise and holes clockwise. Many tools are lenient about this, but some renderers and validators are not.
"coordinates": [[
[-122.43, 37.77], [-122.40, 37.77], [-122.40, 37.79], [-122.43, 37.79], [-122.43, 37.77]
]]
Rule 3: WGS 84 only
Modern GeoJSON has no crs member. Coordinates are WGS 84 degrees. If your data is in meters (Web Mercator) or a local grid, reproject it first.
Keep files small
- Six decimal places is about 10 cm of precision. Anything more just adds bytes.
- Simplify geometries for display zoom levels.
- Put shared attributes in
propertiesand keep them flat. It makes filtering easy.
Security and privacy notes
- Location history and home addresses are personal data. Aggregate or coarsen them before sharing.
- Cap feature counts and coordinate array sizes when you accept uploads.
Open the GeoJSON template and ask the workspace to "add a category property to every feature" or "remove features where open is false", then diff the result.