← Back to Blog

How to Validate and Debug GeoJSON Files

Master GeoJSON validation by learning to detect and fix coordinate order mistakes, winding errors, and self-intersections with free tools and GeoDataTools.

Working with geographic data inevitably leads to broken files. A polygon that refuses to render, coordinates that land in the ocean instead of downtown, or a feature collection that silently drops entries — these issues almost always trace back to malformed GeoJSON. GeoJSON validation is the practice of checking your files against the RFC 7946 specification to catch structural and geometric errors before they cause problems downstream. This guide covers the most common errors, the best tools for catching them, and a practical debugging workflow using GeoDataTools.

Common GeoJSON Validation Errors

Most GeoJSON problems fall into a small number of categories. The table below summarizes the errors you will encounter most frequently, along with their typical symptoms and the recommended fix for each.

ErrorSymptomFix
Wrong coordinate orderFeatures appear mirrored or in the wrong hemisphereUse [longitude, latitude], not [latitude, longitude]
Unclosed polygon ringParser errors or missing polygonsEnsure the first and last coordinates are identical
Wrong winding orderPolygon fills the entire globe except the intended areaApply the right-hand rule (counterclockwise exterior ring)
Self-intersecting polygonRendering artifacts or topology errors in spatial operationsSplit into valid sub-polygons or apply a zero-width buffer
Invalid geometry typeParsers reject the file outrightUse one of the seven standard types defined in RFC 7946
Missing required membersIncomplete features in the outputInclude "type", "geometry", and "properties" on every Feature

Coordinate Order Confusion

The GeoJSON specification requires coordinates in [longitude, latitude] order. This is the opposite of what Google Maps, most GPS apps, and everyday conversation use. Swapping the two values places features at the wrong location — a point meant for Paris (2.35, 48.86) ends up near Somalia (48.86, 2.35) if the order is reversed. Always double-check coordinate order when importing data from spreadsheets or APIs that use latitude-first conventions. For a deeper look at coordinate systems, see our guide on EPSG:4326 vs EPSG:3857.

Unclosed Polygon Rings

RFC 7946 requires that every polygon ring's first and last positions be identical. Some tools silently close rings for you, but strict parsers will reject the file entirely. The fix is straightforward — append a copy of the first coordinate to the end of the ring array.

// ❌ Invalid — ring is not closed
{
  "type": "Polygon",
  "coordinates": [[
    [0, 0], [10, 0], [10, 10], [0, 10]
  ]]
}

// ✅ Valid — first and last positions match
{
  "type": "Polygon",
  "coordinates": [[
    [0, 0], [10, 0], [10, 10], [0, 10], [0, 0]
  ]]
}

Wrong Winding Order

The right-hand rule in RFC 7946 states that exterior rings must follow a counterclockwise winding order, while holes use clockwise winding. When the winding order is reversed, some renderers draw the polygon as a filled globe with a cutout where your intended shape should be. Libraries like Turf.js provide a rewind function that corrects winding order automatically. This is one of the most subtle GeoJSON errors because the file is structurally valid — only the visual output reveals the problem.

import rewind from '@turf/rewind';

const corrected = rewind(geojsonFeature, { reverse: false });

Self-Intersecting Polygons

A polygon whose edges cross each other is geometrically invalid. Self-intersections cause unpredictable behavior in spatial operations such as area calculation, intersection testing, and clipping. Tools like Turf.js's unkinkPolygon can split a self-intersecting polygon into multiple valid polygons. Alternatively, applying a zero-width buffer (buffer(geometry, 0)) in libraries like JSTS or Shapely often resolves simple intersections without altering the intended shape.

GeoJSON Validation Tools

Several free tools can validate your GeoJSON against the specification. Choose the one that best fits your workflow — browser-based for quick checks, npm packages for build pipelines, or a visual tool for spatial debugging.

  • geojsonlint.com — Paste or upload GeoJSON and receive instant validation feedback against the RFC 7946 schema. Best for one-off checks when you need a quick answer.
  • geojson-validation (npm) — A lightweight Node.js library that validates GeoJSON objects programmatically. It returns an array of error messages, making it straightforward to integrate into test suites and CI pipelines.
  • @turf/boolean-valid — Checks whether a geometry is valid according to OGC rules, catching self-intersections and improper ring closure. This complements schema validation by verifying geometric correctness.
  • GeoDataTools — Upload a GeoJSON file and see every feature rendered on an interactive map. Invalid geometries that fail to render or appear in unexpected locations are immediately visible, making it the fastest way to spot coordinate-order and winding-order problems.

Debugging GeoJSON with GeoDataTools

Visual debugging catches errors that schema validators miss. A file can be structurally valid JSON and still contain coordinates in the wrong hemisphere or polygons with microscopic self-intersections. Loading your file into GeoDataTools reveals these problems instantly because you can see exactly where each feature lands on the map.

Start by dragging your .geojson file onto the map. Inspect the attribute table to verify that properties parsed correctly and that feature counts match your expectations. Zoom into individual polygons to check for visual artifacts — tiny spikes or bowtie shapes usually indicate self-intersections. If a feature appears on the wrong side of the world, the coordinate order is likely reversed. Once you identify the issue, fix it in your source data or use one of the programmatic methods described below.

If your original data is in KML format, convert it to GeoJSON first to take advantage of this validation workflow. GeoDataTools processes everything in your browser, so your data never leaves your device — an important consideration when working with sensitive geographic information. For a primer on the format itself, see What is GeoJSON?.

Fixing Invalid Geometries Programmatically

When you need to repair GeoJSON files in bulk, scripting the fixes is more efficient than manual editing. The following Node.js snippet demonstrates a validation and repair pipeline using Turf.js that corrects winding order and splits self-intersecting polygons into valid parts.

import { featureCollection } from '@turf/helpers';
import booleanValid from '@turf/boolean-valid';
import rewind from '@turf/rewind';
import unkinkPolygon from '@turf/unkink-polygon';

function repairFeature(feature) {
  // Fix winding order first
  let repaired = rewind(feature, { reverse: false });

  // Split self-intersecting polygons into valid parts
  if (repaired.geometry.type === 'Polygon' && !booleanValid(repaired.geometry)) {
    const parts = unkinkPolygon(repaired);
    return parts.features;
  }

  return [repaired];
}

function repairCollection(fc) {
  const repairedFeatures = fc.features.flatMap(repairFeature);
  return featureCollection(repairedFeatures);
}

This pipeline first corrects winding order with rewind, then checks geometric validity with booleanValid. Invalid polygons are split into clean sub-polygons using unkinkPolygon. The result is a valid FeatureCollection ready for spatial analysis or rendering in libraries like Leaflet.

Automated GeoJSON Validation in CI/CD Pipelines

If your project stores GeoJSON files in version control, adding validation to your CI/CD pipeline prevents broken files from reaching production. The geojson-validation npm package works well as a pre-commit check or a step in a GitHub Actions workflow.

// validate-geojson.mjs
import { readFileSync } from 'fs';
import GJV from 'geojson-validation';

const file = process.argv[2];
const geojson = JSON.parse(readFileSync(file, 'utf-8'));

if (GJV.valid(geojson)) {
  console.log('✅ ' + file + ' is valid GeoJSON');
  process.exit(0);
} else {
  console.error('❌ ' + file + ' has errors:');
  GJV.isFeatureCollection(geojson, (valid, errors) => {
    errors.forEach(e => console.error('  - ' + e));
  });
  process.exit(1);
}

Run this script against every .geojson file in your repository as part of your test suite. Pair it with a geometric validity check using @turf/boolean-valid to catch issues that schema validation alone cannot detect. Automating these checks ensures that every commit produces spec-compliant GeoJSON, eliminating an entire class of bugs from your geospatial workflows.

FAQ

What is the difference between schema validation and geometric validation?

Schema validation checks that a GeoJSON file follows the RFC 7946 structure — correct type names, properly nested coordinates, and required members like "type" and "geometry". Geometric validation goes further by verifying that shapes are topologically sound: no self-intersections, correct ring closure, and proper winding order. You need both for complete GeoJSON validation.

Can I validate GeoJSON without installing any software?

Yes. Paste your data into geojsonlint.com for instant schema validation, or drag the file into GeoDataTools for visual validation on an interactive map. Both tools run entirely in the browser with no installation or account required.

How do I fix coordinate order in a large GeoJSON file?

Write a script that recursively walks every coordinate array and swaps the first two values. In JavaScript, map each position from [lat, lng] to [lng, lat]. Always verify the result visually in GeoDataTools to confirm that features appear at their correct locations on the map.

Ready to work with your geospatial data?

Visualize, filter, and convert GeoJSON and KML files directly in your browser.

Try GeoDataTools