GeoJSON is the standard format for encoding geographic data in JSON. It's used by mapping libraries, spatial databases, and location APIs to represent points, lines, polygons, and collections of features. If you're working with maps on the web, you'll encounter GeoJSON constantly.

Basic Structure

Every GeoJSON object has a type field. The five geometry types are:

Point

{
  "type": "Point",
  "coordinates": [88.3639, 22.5726]
}

Note the order: longitude first, then latitude. This is the most common source of confusion — GeoJSON uses [lon, lat] while many APIs use (lat, lon).

Advertisement

LineString

{
  "type": "LineString",
  "coordinates": [
    [88.3639, 22.5726],
    [77.2090, 28.6139]
  ]
}

An array of points forming a line. Kolkata to New Delhi.

Polygon

{
  "type": "Polygon",
  "coordinates": [[
    [88.36, 22.57],
    [88.37, 22.57],
    [88.37, 22.58],
    [88.36, 22.58],
    [88.36, 22.57]
  ]]
}

The first and last coordinates must be the same (closing the ring). For polygons with holes, the outer ring comes first, followed by inner rings (holes).

MultiPoint, MultiLineString, MultiPolygon

Arrays of the corresponding geometry types, for representing multiple features of the same type.

GeometryCollection

{
  "type": "GeometryCollection",
  "geometries": [
    {"type": "Point", "coordinates": [88.36, 22.57]},
    {"type": "LineString", "coordinates": [[88.36, 22.57], [77.20, 28.61]]}
  ]
}

Feature Objects

In practice, you usually work with Feature objects, which combine a geometry with properties (metadata):

{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [88.3639, 22.5726]
  },
  "properties": {
    "name": "Kolkata",
    "population": 14850000,
    "country": "India"
  }
}

The properties object can contain any JSON data — strings, numbers, booleans, arrays, or nested objects. This is where you store information about the feature that isn't geographic.

FeatureCollection

A FeatureCollection is the most common top-level GeoJSON structure — an array of features:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {"type": "Point", "coordinates": [88.36, 22.57]},
      "properties": {"name": "Kolkata"}
    },
    {
      "type": "Feature",
      "geometry": {"type": "Point", "coordinates": [77.20, 28.61]},
      "properties": {"name": "New Delhi"}
    }
  ]
}

Using GeoJSON with Leaflet

L.geoJSON(geojsonData, {
  pointToLayer: (feature, latlng) => {
    return L.marker(latlng).bindPopup(
      feature.properties.name
    );
  },
  style: feature => {
    return {color: feature.properties.color || '#3b82f6'};
  }
}).addTo(map);

Leaflet parses GeoJSON and renders it as map layers — markers for points, polylines for lines, polygons for areas. Properties are accessible for styling, popups, and filtering.

Validating GeoJSON

Common GeoJSON errors:

Use a validator like the one at geojson.io or the turf.js library to check your GeoJSON before using it in production.

Coordinate Precision

GeoJSON coordinates should use no more than 6 decimal places (about 10cm precision). More precision wastes space — 8 decimal places gives sub-millimetre accuracy, which is meaningless for most geographic data. Round coordinates before storing:

Math.round(lon * 1e6) / 1e6

The map tool on this site lets you create markers, draw shapes, and export the result as GeoJSON. Everything runs in your browser — your location data never leaves your device.