Registry / serialization / geojson

geojson

JSON →
library3.3.0pypypi✓ verified 26d ago

Python bindings and utilities for GeoJSON. This library provides functions for encoding and decoding GeoJSON formatted data, classes for all GeoJSON Objects as defined by the GeoJSON Format Specification, and implements the Python `__geo_interface__` Specification. It is currently at version 3.2.0 and is actively maintained by the Jazzband community, compatible with Python 3.7 and above.

pip install geojson
INSTALL
IMPORT
SIG · GEOJSON
G
geojson
serializationpythonv3.3.0
Install
1.5s avg
Import
11ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.012s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.010s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Point
from geojson import Point
LineString
from geojson import LineString
Polygon
from geojson import Polygon
Feature
from geojson import Feature
FeatureCollection
from geojson import FeatureCollection
dumps
from geojson import dumps
loads
from geojson import loads
import json; json.loads(...)
Using `json.loads` directly will return a plain dictionary, losing the GeoJSON object methods and attributes. Use `geojson.loads` for richer objects.
dump
from geojson import dump
load
from geojson import load
import json; json.load(...)
Using `json.load` directly will return a plain dictionary, losing the GeoJSON object methods and attributes. Use `geojson.load` for richer objects.

This quickstart demonstrates how to create common GeoJSON objects like `Point`, `Feature`, and `FeatureCollection`, and then serialize them into a GeoJSON formatted string using `geojson.dumps`.

from geojson import Point, Feature, FeatureCollection, dumps # Create a Point geometry point = Point((-115.81, 37.24)) # Create a Feature with the Point geometry and properties feature = Feature(geometry=point, properties={"name": "Area 51"}) # Create a FeatureCollection containing the feature feature_collection = FeatureCollection([feature]) # Serialize the FeatureCollection to a GeoJSON string with indentation geojson_str = dumps(feature_collection, indent=2) print(geojson_str)
Debug
Known issues
breakingVersion 3.0.0 dropped support for Python 2 and now requires Python 3.7 or newer. Additionally, the `crs` module and related features were removed to strictly conform to the official GeoJSON specification, which mandates WGS84 coordinates.
fix
Ensure your project uses Python 3.7+ and update any code relying on custom CRS definitions or the `geojson.crs` module.
affects: >=3.0.0
gotchaWhen loading or decoding GeoJSON data, always use `geojson.load` or `geojson.loads` instead of the standard `json.load` or `json.loads`. Using the standard `json` module will return plain Python dictionaries, losing the rich GeoJSON object functionality and validation provided by this library.
fix
Replace `json.load(f)` with `geojson.load(f)` and `json.loads(s)` with `geojson.loads(s)`.
affects: All
gotchaGeoJSON object classes in this library apply a default coordinate precision of 6 decimal places (approximately 0.1 meters). While this is often suitable, it may lead to data loss for highly precise geospatial coordinates if not explicitly managed.
fix
Adjust the `precision` attribute when creating GeoJSON objects or set `geojson.DEFAULT_PRECISION` globally if higher precision is required. Be aware that this can increase file size.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'geojson'
The 'geojson' library is not installed in the Python environment where you are running your code, or the environment is not correctly activated.
fix
Install the package using pip: `pip install geojson` (or `pip3 install geojson` for Python 3 specific installations).
ValueError: Expected 0 or more linear rings, got (...)
This error occurs when creating a `geojson.Polygon` object because the coordinates are not nested correctly according to the GeoJSON specification. A Polygon's coordinates should be a list of linear rings, where each linear ring is itself a list of coordinate pairs, and the first and last coordinate pair of each linear ring must be identical. A common mistake is providing a single linear ring as a direct list of points instead of a list containing that list.
fix
Ensure the coordinates for a `Polygon` are a list of lists of `(longitude, latitude)` tuples. For a simple polygon, it should be `[[exterior_ring_coords]]`. Example: `geojson.Polygon([[(0, 0), (1, 1), (1, 0), (0, 0)]])`
AttributeError: 'str' object has no attribute '_geom'
This error typically arises when you are attempting to perform a geospatial operation (often with a library like Shapely) that expects a geometry object, but you are instead providing a raw GeoJSON string. The `_geom` attribute is internal to some geometry libraries and is not present on a standard Python string.
fix
If you have a GeoJSON string, you need to parse it into a Python GeoJSON object (or a Shapely geometry object) before using it in operations that expect a geometry. Use `geojson.loads(json_string)` to get a `geojson` object, or `shapely.geometry.shape(geojson.loads(json_string))` to get a Shapely object.
AttributeError: 'Map' object has no attribute 'GeoJson'
This error occurs when attempting to add GeoJSON data to a Folium map using a non-existent method or attribute. In Folium, `GeoJson` is a separate class used to create a GeoJSON layer, which is then added to the map using `add_to()` or `add_child()`, not by directly accessing an attribute on the map object.
fix
Create a `folium.GeoJson` object separately and then add it to your map instance. Example: `geojson_data = geojson.loads(my_geojson_string)`; `folium.GeoJson(geojson_data).add_to(my_map)` or `my_map.add_child(folium.GeoJson(geojson_data))`.
Upgrade
Version history
3.3.0latest on PyPI · released May 28, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
6
Resources
geojson — pip install geojson · libregistry