How to Read GeoJSON in Python with GeoPandas

Problem statement

If you have a .geojson file and need to use it in Python, the practical goal is usually to load that GeoJSON file into a GeoDataFrame so you can inspect attributes, filter features, map the layer, or run spatial analysis.

Common GIS cases include:

  • administrative boundaries downloaded from an open data portal
  • points of interest exported from a web map
  • parcel or land-use data received from another system
  • GeoJSON returned by an API or field data workflow

Quick answer

To read a GeoJSON file in Python with GeoPandas, use geopandas.read_file():

import geopandas as gpd

gdf = gpd.read_file("data/city-boundaries.geojson")

This returns a GeoDataFrame. After loading, check:

  • the file path is correct
  • the geometry column loaded properly
  • the CRS is what you expect

Step-by-step solution

Install GeoPandas if needed

If GeoPandas is not installed yet:

pip install geopandas

If you use Anaconda or Miniconda, this is often more reliable:

conda install -c conda-forge geopandas

Import GeoPandas

For this task, you only need:

import geopandas as gpd

Read the GeoJSON file

Use read_file() to load the file into a GeoDataFrame:

import geopandas as gpd

gdf = gpd.read_file("data/city-boundaries.geojson")

Now gdf contains:

  • attribute fields such as district name, population, or land-use type
  • a geometry column with points, lines, or polygons

Preview the data

Check the first rows to confirm the file loaded correctly:

print(gdf.head())

You can also inspect the column names:

print(gdf.columns)

This helps confirm:

  • expected fields are present
  • records look reasonable
  • geometry values exist

Check geometry type and CRS

After reading the file, inspect geometry types and coordinate reference system:

print(gdf.geom_type.unique())
print(gdf.crs)

Typical geometry types include:

  • Point
  • LineString
  • Polygon
  • MultiPolygon

GeoJSON data is commonly expected in WGS84 longitude/latitude (EPSG:4326), but you should still confirm the CRS before plotting, buffering, joining, or reprojecting.

Filter features after loading

A common next step is selecting records by attribute:

central_district = gdf[gdf["district"] == "Central"]
print(central_district)

This creates a smaller GeoDataFrame for the next GIS task, such as mapping, clipping, or exporting.

Code examples

Example 1: Read a local GeoJSON file into a GeoDataFrame

import geopandas as gpd

boundaries = gpd.read_file("data/city-boundaries.geojson")

print(type(boundaries))
print(boundaries.head())

Expected result: boundaries is a GeoDataFrame ready for GIS work.

Example 2: Check columns, geometry types, and CRS

import geopandas as gpd

boundaries = gpd.read_file("data/city-boundaries.geojson")

print("Columns:")
print(boundaries.columns)

print("\nGeometry types:")
print(boundaries.geom_type.unique())

print("\nCRS:")
print(boundaries.crs)

Use this to verify:

  • available attribute fields
  • the geometry column loaded
  • features are points, lines, or polygons
  • CRS metadata is defined

Example 3: Filter features after reading

import geopandas as gpd

land_use = gpd.read_file("data/land-use.geojson")

residential = land_use[land_use["use_type"] == "Residential"]

print(residential.head())
print(f"Selected {len(residential)} features")

Now residential is a filtered GeoDataFrame that can be mapped, saved, or used in analysis.

Example 4: Read GeoJSON from a URL

import geopandas as gpd

url = "https://example.com/data/city-boundaries.geojson"
gdf = gpd.read_file(url)

This can work when the URL points directly to a valid GeoJSON file, but remote reads may depend on your GDAL/Fiona/pyogrio setup and how the server responds.

Explanation

geopandas.read_file() reads a spatial file and converts it into a GeoDataFrame.

For a GeoJSON file, that usually means two parts are loaded together:

  • attributes: non-spatial fields such as names, IDs, categories, or populations
  • geometry: spatial features such as points, lines, or polygons

A GeoDataFrame behaves like a pandas DataFrame, but it also supports GIS operations. After loading a GeoJSON file, you can do standard table tasks like:

  • inspect columns
  • filter rows
  • sort values

You can also do spatial tasks like:

  • plot features
  • reproject coordinates
  • run spatial joins
  • calculate area, length, or distance

Checking the CRS matters because later GIS operations depend on correct coordinate metadata. If the CRS is wrong or missing, overlays, measurements, and map alignment may be incorrect.

Edge cases or notes

File path problems

A common reason GeoJSON does not load is an incorrect file path.

Relative path example:

gdf = gpd.read_file("data/city-boundaries.geojson")

Absolute path example:

gdf = gpd.read_file("/home/user/project/data/city-boundaries.geojson")

If the file is not found, check:

  • the filename and extension
  • your current working directory
  • whether the path uses the correct slashes for your OS

Missing or invalid geometry

Some GeoJSON files contain empty or invalid geometries. Check for missing geometry values after loading:

print(gdf.geometry.isna().sum())

You can also inspect validity:

print(gdf.is_valid.value_counts())

Invalid geometries may cause problems later in overlays, dissolves, or exports.

CRS may be missing or unexpected

Do not assume the CRS is correct just because the file loaded successfully. Always inspect it:

print(gdf.crs)

If CRS metadata is missing, you may need to assign the correct CRS manually before doing spatial analysis.

Large GeoJSON files can be slow

Large GeoJSON files can be slower to read and more memory-heavy than formats built for analysis. This is common with files exported from web tools or APIs.

If performance becomes a problem, consider converting the dataset later to a format such as GeoPackage or Parquet.

If you are new to vector data in Python, start with GeoPandas basics for spatial vector data in Python.

For a similar file-reading workflow, see How to Read a Shapefile in Python with GeoPandas.

If you need the next step after loading, see How to Reproject Spatial Data in Python (GeoPandas).

If you need to save edited data back out, read How to Export GeoJSON in Python with GeoPandas.

FAQ

Can GeoPandas read GeoJSON directly?

Yes. GeoPandas can read GeoJSON directly with geopandas.read_file(). You do not need to parse the file manually for standard GIS workflows.

What does geopandas.read_file() return for a GeoJSON file?

It returns a GeoDataFrame with both attribute columns and a geometry column, so the data is ready for mapping and spatial analysis.

How do I check if my GeoJSON loaded with the correct CRS?

Use:

print(gdf.crs)

Check this before reprojecting, joining, or measuring distances and areas.

Can I read GeoJSON from a URL instead of a local file?

Often yes:

gdf = gpd.read_file("https://example.com/data.geojson")

This works best when the URL points directly to a valid GeoJSON file and your local GIS Python stack supports remote reading.