Convert GeoJSON with GDAL: troubleshooting guide

This troubleshooting guide explains how to diagnose and fix common failures when converting GeoJSON with GDAL. It uses `ogrinfo` to inspect the source, `ogr2ogr` to perform controlled conversions, and the GDAL GeoJSON driver documentation to clarify behavior around coordinate reference systems, RFC 7946 output, mixed geometries, attributes, precision, remote files, and virtual file systems. The guide focuses on finding the first failing stage instead of repeatedly changing command-line options at random.

GeoJSON conversion problems are often caused by an incorrect assumption about what failed. The input may be valid JSON but not a recognizable GeoJSON datasource; the file may open correctly but contain an unexpected layer name; the geometries may be valid but use the wrong coordinate reference system; or the conversion may succeed while silently changing precision, dimensions, field types, or native JSON members. GDAL provides separate tools for inspecting and transforming vector data, so the most dependable workflow is to inspect first, convert a small or bounded sample, validate the result, and only then run the full conversion.

How EDK fits

For: GIS analysts, data engineers, developers, and geospatial operators who use GDAL or `ogr2ogr` to convert GeoJSON into formats such as GeoPackage, Shapefile, FlatGeobuf, or another GeoJSON dataset.

GeoJSON conversion is a practical boundary between raw location data and a usable representation of the physical world. A GeoJSON file can describe roads, buildings, parks, waterways, service locations, permits, or other geographic features, but those features are only useful for world-model work when their geometry, coordinate reference system, attributes, and provenance survive the conversion in a known form. GDAL helps make that boundary explicit: it can inspect the source layer, transform coordinates, select or filter features, write to a different spatial format, and expose the resulting data for mapping or geographic computation. In an E2-oriented workflow, a carefully validated GDAL conversion can be one preparation step before features are searched, compared, ranked, aggregated, or related to other physical features. GDAL itself is not an E2 capability, and this guide does not imply that GDAL supplies a global place index, live data, routing, or any other capability beyond the documented conversion and inspection operations.

  • •Normalize incoming GeoJSON describing physical features such as roads, buildings, waterways, public assets, or service locations before loading it into a broader world-model workflow. The useful E2 connection is data readiness: geometry, CRS, attributes, and conversion assumptions become explicit before geographic search or computation.
  • •Convert and validate multiple geographic layers into analysis-friendly formats so that downstream workflows can compare features, calculate proximity, aggregate observations by area, or relate incidents and infrastructure to the surrounding physical environment. GDAL performs the conversion; the E2 connection is the resulting ability to reason consistently about real places rather than treating each file as an isolated artifact.
Primary tools
`ogrinfo` for inspection and `ogr2ogr` for conversion.
GeoJSON driver
Built into GDAL by default according to the official vector-driver documentation.
CRS assignment
`-a_srs` assigns or labels the source CRS; it does not reproject coordinates.
CRS transformation
`-t_srs` requests transformation into a target CRS.
RFC 7946 output
Use `-lco RFC7946=YES` when standards-oriented GeoJSON output is required.
Validation rule
Reopen and inspect the destination; a successful command is not sufficient evidence of geographic correctness.

The EDK outcome

Before you start

A working GDAL installation that provides `ogrinfo` and `ogr2ogr`.

A GeoJSON file or a documented, accessible URL containing GeoJSON.

Authoritative knowledge of the source coordinate reference system, or a documented decision that no safe reprojection is possible.

A target format and a clear requirement for whether coordinates, fields, geometry types, precision, and extra JSON members must be preserved.

A small test copy or bounded sample for safe experimentation before converting the complete dataset.

Learning objectives

Diagnose whether GDAL can recognize and open a GeoJSON source.

Distinguish CRS assignment from coordinate transformation.

Convert GeoJSON with `ogr2ogr` while controlling output format, layer name, fields, and target CRS.

Produce RFC 7946 GeoJSON when that standard is required.

Validate feature counts, extents, geometry types, fields, CRS, and representative features after conversion.

Identify when a conversion succeeded technically but produced an unsuitable or geographically incorrect result.

Verification

The input opens successfully with `ogrinfo` in read-only mode.

The reported layer name is used correctly in commands that require a source layer.

The source CRS is known or explicitly documented as unavailable; no CRS has been guessed.

The output reopens with `ogrinfo` without errors.

The output feature count is equal to the expected count, allowing for intentional filters or failed records that are investigated.

The output extent is geographically plausible and consistent with the intended CRS.

Representative point, line, and polygon features retain the intended location and geometry structure.

The output field schema, null handling, identifiers, and important attributes meet the receiving system’s requirements.

The exact GDAL version, command, options, source reference, and conversion date are recorded.

Troubleshooting

If GDAL cannot identify the file, inspect the first bytes and confirm that the response is GeoJSON rather than HTML, XML, or an authentication error. Check the path and try explicit GeoJSON driver selection where supported.

If the layer name is wrong, run `ogrinfo -ro -al -so` and use the name reported by GDAL. A GeoJSON datasource commonly exposes one layer, but its name can be derived from a top-level `name`, the filename, or `OGRGeoJSON`. (gdal.org)

If the output appears thousands of kilometers away, stop and investigate CRS metadata. Do not repair the result by visually shifting coordinates. Determine whether the source is geographic, projected, or missing authoritative CRS information.

If coordinates are reversed, distinguish between malformed input and a consumer that expects a different coordinate convention. RFC 7946 GeoJSON uses geographic coordinates in longitude-latitude order; validate a known feature against its expected location. (gdal.org)

If mixed geometry types cause downstream errors, inspect the source geometry summary and decide whether the receiving system can accept a heterogeneous layer. If not, split by geometry type or consider the driver’s `GEOMETRY_AS_COLLECTION` behavior rather than assuming all features are polygons or all are points. (gdal.org)

If attributes disappear or change type, compare the source and destination schemas. Use `-select` to define the intended fields, inspect list and nested attributes, and choose an output format whose field model matches the data.

If the output is much larger or less precise than expected, review `COORDINATE_PRECISION`, `SIGNIFICANT_FIGURES`, native-data preservation, and whether the conversion is retaining properties that are not needed by the receiving application. (gdal.org)

If a remote or compressed source fails intermittently, download a verified local copy for diagnosis or use the documented GDAL virtual-file syntax. Separate network, authentication, archive-path, and GeoJSON parsing failures instead of treating them as one conversion problem. (gdal.org)

If a large conversion exhausts memory or takes too long, avoid dumping all features with `ogrinfo`, test the driver and output on a bounded sample, reduce unnecessary fields, and consider a more suitable intermediate format or database-backed workflow.

Next steps

Add conversion commands to a version-controlled script with explicit source, destination, CRS, layer name, and creation options.

Store a machine-readable inspection report from `ogrinfo -json` with the converted dataset when reproducibility matters.

Run geometry and CRS checks in the downstream analysis environment, such as GeoPandas or a spatial database, rather than relying only on visual inspection.

For recurring feeds, track source version, retrieval time, GDAL version, feature count, extent, and schema changes so that physical-world analyses can distinguish data updates from conversion regressions.

When converted features will be combined with roads, buildings, waterways, public assets, incidents, or other geographic layers, standardize CRS and document the spatial relationship assumptions before computing proximity, overlays, or regional summaries.

What GDAL is converting—and why the distinction matters

GDAL’s vector utilities operate through OGR drivers. The GeoJSON driver reads and writes GeoJSON and presents it as a datasource containing one OGR layer. A GeoJSON source may be a local `.geojson` or `.json` file, a URL, or text passed directly to the driver. A top-level `FeatureCollection` becomes a layer containing its features; a top-level GeoJSON geometry or feature is treated as a one-feature layer. (gdal.org)

The conversion command is usually shaped like `ogr2ogr <destination> <source> [<layer>]`. The destination format can be inferred from the filename in many cases, but specifying it with `-f` makes scripts easier to read and less dependent on filename conventions. `ogr2ogr` also supports coordinate-system assignment and transformation, field selection, spatial and attribute filtering, geometry-type controls, layer naming, and creation options. (gdal.org)

  • •Inspection answers: Can GDAL open the input? What is the layer called? What geometry types and fields are present? Is a CRS reported? What are the extent and feature count?
  • •Conversion answers: Which output driver is being used? Are coordinates transformed? Are fields selected or remapped? Are layer creation options changing the representation?
  • •Validation answers: Does the output reopen? Does it have the expected spatial extent, geometry, field schema, and coordinate interpretation?

Prerequisites and a controlled diagnostic setup

Install a GDAL distribution that includes the command-line utilities `ogrinfo` and `ogr2ogr`. Confirm the executable and version before debugging. Version differences matter because current GDAL documentation includes options and behaviors added in particular releases, including newer driver-selection and output features.

Keep a small copy of the source if the original is large or remote. Do not begin by converting the entire dataset. First establish a reproducible working directory and record the exact input path, GDAL version, source URL if applicable, intended output format, and intended CRS.

  • •`ogrinfo --version`
  • •`ogr2ogr --version`
  • •`ogrinfo --formats | grep -i geojson` on Unix-like systems, or use `ogrinfo --formats` and search for GeoJSON on Windows
  • •`ogr2ogr --help` to confirm the options available in the installed version.

Step 1: inspect the GeoJSON before converting it

Start with read-only inspection. The `-ro` flag prevents update mode, while `-al -so` requests a summary across layers without dumping every feature. This is safer for large files than immediately listing all features. `ogrinfo` reports information such as the layer, projection, schema, feature count, and extent. (gdal.org)

For a local file, run:

  • •`ogrinfo -ro -al -so input.geojson`
  • •`ogrinfo -ro -al -so -json input.geojson`
  • •`ogrinfo -ro input.geojson OGRGeoJSON -limit 3 -geom SUMMARY` if the layer is reported as `OGRGeoJSON`.
  • •If the filename is ambiguous or automatic detection fails on a URL or unusual file, try `ogrinfo -ro -if GeoJSON input.data` on GDAL versions that support the `-if` option. The GeoJSON driver documentation also describes the `GeoJSON:` prefix as a way to remove ambiguity. (gdal.org)
  • •Look for these specific conditions: an absent CRS, an unexpected extent, a geometry type that is mixed or unknown, fields that vary across features, a top-level object that is not a `FeatureCollection`, or an input that is actually an HTML error page returned by a URL. A file extension alone does not prove that the contents are valid GeoJSON.

Step 2: run the smallest useful conversion

Once the source opens, convert it to a format that is easy to inspect. GeoPackage is often a useful diagnostic target because it stores a named layer in a single SQLite-based file and avoids some of the field-name and type limitations associated with older interchange formats. The command below creates a GeoPackage layer named `features`:

  • •`ogr2ogr -f GPKG output.gpkg input.geojson -nln features`
  • •`ogr2ogr -f GPKG output_sample.gpkg input.geojson -nln features -limit 100` if the installed version and driver support the intended bounded test workflow.
  • •`ogr2ogr -f GPKG output.gpkg input.geojson -nln features -select id,name,status` to restrict attributes when those fields exist.
  • •After conversion, inspect the destination rather than trusting the command’s completion message:
  • •`ogrinfo -ro -al -so output.gpkg`
  • •`ogrinfo -ro output.gpkg features -limit 3 -geom SUMMARY`.
  • •If the destination opens and its extent, count, geometry, fields, and CRS match expectations, repeat the conversion without the sample limitation. Keep the successful command in a script or documented run log so the operation can be reproduced.

Step 3: make GeoJSON CRS and RFC 7946 behavior explicit

GeoJSON conversions frequently fail at the boundary between legacy GeoJSON behavior and RFC 7946 behavior. The GDAL GeoJSON driver can write RFC 7946 output with the layer creation option `RFC7946=YES`. In that mode, coordinates are geographic over the WGS 84 ellipsoid, and GDAL reprojects from another layer CRS when necessary. The output may also use RFC 7946 polygon orientation, antimeridian handling, and a default of seven decimal places. (gdal.org)

To create RFC 7946 GeoJSON from a source whose CRS is already correctly identified, use:

  • •`ogr2ogr -f GeoJSON output.json input.gpkg -lco RFC7946=YES`
  • •`ogr2ogr -f GeoJSON output.json input.gpkg source_layer -t_srs EPSG:4326 -lco RFC7946=YES`.
  • •If the input lacks a CRS but you know what the coordinates represent, assign it with `-a_srs`, then transform if needed:
  • •`ogr2ogr -f GeoJSON output.json input.geojson -a_srs EPSG:3857 -t_srs EPSG:4326 -lco RFC7946=YES`.
  • •Do not copy that CRS command without confirming the source. EPSG:3857 is only an example. If the actual coordinates are longitude and latitude, assigning EPSG:3857 would make the data wrong. When the source CRS is genuinely unavailable, the correct response is to identify it from authoritative metadata or report that reprojection cannot be performed safely.

Step 4: validate geometry, attributes, and output semantics

A conversion can complete while producing a result that is unsuitable for the next system. Validate at least the feature count, extent, geometry type, CRS, field names, null behavior, and a few representative geometries. Compare a known coordinate or bounding box from the source with the destination.

The GeoJSON driver supports heterogeneous geometry layers by default. It can preserve different geometry types in one layer, while `GEOMETRY_AS_COLLECTION=YES` can wrap geometries as collections when a homogeneous representation is required. The driver also derives a union of feature properties when features do not share identical property schemas. Those behaviors can be useful, but they may surprise consumers that expect one geometry type or a stable field definition. (gdal.org)

  • •Reopen the output with `ogrinfo`; do not validate only by opening it in a web map.
  • •Check that longitude and latitude are in the expected order for GeoJSON output.
  • •Test a polygon near a boundary or antimeridian if those cases matter to your data.
  • •Compare a few source and destination feature properties, especially arrays, dates, long strings, and nullable fields.
  • •Record the source CRS, target CRS, GDAL version, command, and output creation options with the converted dataset.

Workflow

01

1. Confirm the installed GDAL tools

Run `ogrinfo --version` and `ogr2ogr --version`. Record the versions because available options and driver behavior can differ between releases. Confirm that the GeoJSON driver appears in `ogrinfo --formats`.

ogrinfo --version
ogr2ogr --version
ogrinfo --formats
02

2. Inspect the source in read-only mode

Use a summary inspection before converting. This reveals whether the source opens, which layer name to use, what CRS and geometry types are reported, and whether the extent and feature count look plausible.

ogrinfo -ro -al -so input.geojson
ogrinfo -ro -al -so -json input.geojson
03

3. Convert a small, inspectable result

Start with a GeoPackage or another format that is easy to reopen and inspect. Set the destination layer name explicitly. If necessary, select only known fields or test a limited sample before running the full conversion.

ogr2ogr -f GPKG test-output.gpkg input.geojson -nln features
ogrinfo -ro -al -so test-output.gpkg
04

4. Make CRS behavior explicit

Use `-a_srs` only when assigning the known source CRS. Use `-t_srs` when transforming coordinates. If producing standards-oriented GeoJSON, add `-lco RFC7946=YES` and validate the result afterward.

ogr2ogr -f GeoJSON output.json input.gpkg -t_srs EPSG:4326 -lco RFC7946=YES
05

5. Validate the complete output

Reopen the final destination and compare its count, extent, CRS, geometry types, fields, and representative features with the source. Preserve the command and metadata alongside the output.

ogrinfo -ro -al -so final-output.gpkg
ogrinfo -ro final-output.gpkg features -limit 3 -geom SUMMARY

Questions teams ask

Why does `ogr2ogr` say it cannot open my GeoJSON file?

First run `ogrinfo -ro -al -so input.geojson`. Check the path, permissions, JSON syntax, and whether the downloaded content is actually GeoJSON rather than an HTML or authentication error. If driver detection is ambiguous, try `ogrinfo -ro -if GeoJSON input.geojson` where supported, or use the `GeoJSON:` prefix described in the official driver documentation. (gdal.org)

Why did my converted data move to the wrong location?

The most common cause is incorrect CRS handling. `-a_srs` labels coordinates; it does not transform them. Use `-t_srs` for a coordinate transformation, but only after confirming the true source CRS from authoritative metadata. Never substitute EPSG:4326 merely because the destination is GeoJSON.

How do I convert GeoJSON to RFC 7946 GeoJSON?

Use the GeoJSON output driver and set the layer creation option: `ogr2ogr -f GeoJSON output.json input.gpkg -lco RFC7946=YES`. If the source is not already in the required geographic CRS, add an appropriate `-t_srs` transformation. Then reopen the output with `ogrinfo` and inspect its CRS, extent, geometry, and feature count. (gdal.org)

Why are fields missing or changed after conversion?

GeoJSON features may have different property sets and values with different types. OGR builds a layer schema from the available properties, but the destination format may impose stricter field-name, type, length, or nullability rules. Use `ogrinfo` to inspect the source schema, then use `-select`, field-mapping options, or a more suitable destination format.

Can GDAL convert a remote GeoJSON URL?

The GeoJSON driver supports URL sources, and GDAL virtual file systems support network and archive access in documented configurations. Test the URL with `ogrinfo` first, confirm authentication and content type, and avoid assuming that a browser-visible URL is a stable machine-readable endpoint. (gdal.org)

Keep exploring

Sources

More in Guides