The Complete Guide to GeoJSON: Format, Tools, and Best Practices
Everything you need to know about GeoJSON - the universal format for geographic data. Learn the structure, geometry types, and how to work with GeoJSON effectively.
Table of Contents
GeoJSON has become the de facto standard for representing geographic data on the web. It’s human-readable, widely supported, and perfect for web mapping applications.
What is GeoJSON?
GeoJSON is a JSON-based format for encoding geographic data structures. It can represent:
- Points (locations)
- Lines (paths, routes)
- Polygons (areas, boundaries)
- Collections of these geometries
Basic Structure
Every GeoJSON object has a type property. The most common structure is a FeatureCollection:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-122.4194, 37.7749]
},
"properties": {
"name": "San Francisco",
"population": 874961
}
}
]
}
Geometry Types
Point
A single location:
{
"type": "Point",
"coordinates": [-122.4194, 37.7749]
}
Coordinates are [longitude, latitude] (note: longitude comes first!).
LineString
A series of connected points:
{
"type": "LineString",
"coordinates": [
[-122.4194, 37.7749],
[-118.2437, 34.0522],
[-117.1611, 32.7157]
]
}
Polygon
A closed area with an outer boundary and optional holes:
{
"type": "Polygon",
"coordinates": [
[
[-122.5, 37.8],
[-122.3, 37.8],
[-122.3, 37.7],
[-122.5, 37.7],
[-122.5, 37.8]
]
]
}
The first and last coordinates must be identical to close the polygon.
MultiPoint, MultiLineString, MultiPolygon
Collections of the basic types:
{
"type": "MultiPolygon",
"coordinates": [
[[[...]]],
[[[...]]]
]
}
GeometryCollection
Mixed geometry types:
{
"type": "GeometryCollection",
"geometries": [
{ "type": "Point", "coordinates": [0, 0] },
{ "type": "LineString", "coordinates": [[0, 0], [1, 1]] }
]
}
Features and Properties
Features wrap geometries and add properties:
{
"type": "Feature",
"id": "sf-1",
"geometry": {
"type": "Point",
"coordinates": [-122.4194, 37.7749]
},
"properties": {
"name": "San Francisco",
"country": "USA",
"timezone": "America/Los_Angeles",
"population": 874961,
"founded": 1776
}
}
Properties can contain any valid JSON: strings, numbers, booleans, arrays, nested objects.
Coordinate Reference Systems
GeoJSON uses WGS84 (EPSG:4326) by default. Coordinates are:
- Longitude: -180 to 180
- Latitude: -90 to 90
- Altitude (optional): meters above WGS84 ellipsoid
{
"type": "Point",
"coordinates": [-122.4194, 37.7749, 100]
}
If your data is in a different CRS, convert it before creating GeoJSON. Our GeoJSON Converter can transform coordinates between systems.
Best Practices
1. Use Consistent Winding Order
For polygons, the outer ring should be counter-clockwise, holes clockwise. This follows the right-hand rule and ensures compatibility.
2. Keep Precision Reasonable
Six decimal places give ~10cm precision—more than enough for most applications:
// Good
[-122.419416, 37.774929]
// Excessive
[-122.41941642761231, 37.77492912847123]
3. Validate Your GeoJSON
Invalid GeoJSON causes silent failures. Common issues:
- Unclosed polygons
- Wrong coordinate order
- Invalid geometry types
- Missing required properties
Use our GeoJSON Viewer to validate and visualize your data.
4. Include Bounding Boxes for Large Files
Add a bbox property for faster spatial queries:
{
"type": "FeatureCollection",
"bbox": [-122.5, 37.7, -122.3, 37.9],
"features": [...]
}
5. Use Feature IDs
IDs enable efficient updates and lookups:
{
"type": "Feature",
"id": "building-123",
...
}
Common Operations
| Operation | Description |
|---|---|
| Parse | Convert JSON string to object |
| Validate | Check structure and geometry validity |
| Transform | Convert to different CRS |
| Simplify | Reduce coordinate count |
| Buffer | Create area around geometries |
| Merge | Combine multiple files |
Tools and Libraries
JavaScript
- Turf.js: Comprehensive geospatial analysis
- Mapbox GL JS: Web map rendering
- Leaflet: Lightweight mapping
Python
- GeoPandas: Pandas for geospatial data
- Shapely: Geometry operations
- Fiona: File I/O
Online Tools
- GeoJSON Viewer - Visualize GeoJSON
- GeoJSON Converter - Transform coordinates
- GeoJSON to CSV - Export to spreadsheet
GeoJSON vs Other Formats
| Format | Pros | Cons |
|---|---|---|
| GeoJSON | Human-readable, web-native | Large file sizes |
| Shapefile | Widely supported | Multiple files, 2GB limit |
| GeoPackage | SQLite-based, efficient | Less web support |
| KML | Google Earth support | XML verbosity |
| TopoJSON | Smaller files | Requires processing |
Example: City Points
Here’s a complete example with multiple cities:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-0.1276, 51.5074]
},
"properties": {
"name": "London",
"country": "UK",
"population": 8982000
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [2.3522, 48.8566]
},
"properties": {
"name": "Paris",
"country": "France",
"population": 2161000
}
}
]
}
Try pasting this into our GeoJSON Viewer to see it on a map!
Conclusion
GeoJSON strikes an excellent balance between human readability and machine processability. By following these best practices, you’ll create interoperable geographic data that works across platforms and tools.