# GeoJSON validator

> Paste GeoJSON or drop a file to check it against RFC 7946. Every problem is explained in plain words with its line number, and most have a one-click fix. Free, no account needed.

Open the tool: https://spatibase.com/tools/geojson-validator/

The Spatibase GeoJSON validator checks GeoJSON against RFC 7946 in your web browser and explains each problem in plain words, with its line number. It fixes the common ones in one click (open rings, winding order, coordinates as text, a legacy crs member, too many decimals), shows the data on a map and tells you whether the file will import into Spatibase. It’s free with no account, checks files up to 50 MB, and nothing is uploaded.

What you get beyond a plain “invalid”:

- **Where, not just what.** Each problem names its lines and a path such as `features[12].geometry`.
- **Fixes that check again.** After a fix the text is checked anew, so the list and the map always match what you download.
- **Honest limits.** Swapped coordinates that stay in range can’t be detected (the map shows them), and self-intersections are found, not fixed.

## What it does
- Paste GeoJSON or open a .geojson or .json file
- Checks JSON syntax and the rules of RFC 7946
- Errors, warnings and notes with line numbers
- One-click fix per problem, or Fix all
- Map preview with a Swap longitude and latitude button
- Says what would import into Spatibase, and why not
- Download the fixed GeoJSON, copy it, or save CSV
- Runs in the browser: nothing is uploaded

## How to validate GeoJSON
Paste, check, fix, download: all on this page.

1. Press Paste GeoJSON, paste it and press Check (Ctrl+Enter or ⌘+Enter), or drop a .geojson file. No file? Open the sample: Barcelona places with typical mistakes.
2. Read the list: errors, then warnings and notes, each with its lines.
3. Press a problem’s fix, or Fix all. The text is checked again each time.
4. Look at the map. A point on the wrong continent has longitude and latitude swapped: press Swap longitude and latitude.
5. Download or copy the fixed GeoJSON, or press Save to Spatibase (free) to put it in a free Spatibase project.

## Input, output and limits
- **Input:** GeoJSON pasted into the box (Paste GeoJSON, then Check or Ctrl+Enter), or a .geojson or .json file: a FeatureCollection, a single Feature or a bare geometry. Up to 50 MB; above about 20 MB the check can take a few seconds.
- **Reports:** every problem with its severity (error, warning, note), its count and its first 5 places (line number and a path such as `features[12].geometry`). Self-intersections are checked in rings of up to 2,000 positions.
- **Fixes:** one button per problem, or Fix all. The text is checked again after each fix. Swap longitude and latitude is always offered, since swapped values inside both ranges can’t be detected.
- **Import check:** how many features would import into Spatibase, import without a location (`null` geometry) or be skipped, with the importer’s reason. Up to 10,000 features per import.
- **Downloads:** the fixed GeoJSON (pretty-printed with 2 spaces if the input had line breaks, else one line), Copy GeoJSON, and CSV.
- **Privacy:** the text is checked in your browser and never uploaded.
- Try it with a sample: https://spatibase.com/tools/geojson-validator/?sample=1
- Download the sample file (the one Open a sample opens: Barcelona places with typical mistakes put in on purpose): https://spatibase.com/tools/samples/barcelona-broken.geojson

## What the GeoJSON checker looks for, and how it fixes it
**Three levels.** Errors make the file invalid or stop it importing; warnings break an RFC 7946 recommendation or look wrong; notes are worth knowing.

The errors, and what each fix does:

- **Broken JSON.** Line, column and likely cause (trailing comma, single quotes, a comment, `NaN`). When trailing commas, comments or a BOM are the only problems, one click removes them.
- **Not GeoJSON.** A bare array of features is wrapped in a `FeatureCollection`; a `type` in the wrong case (`"featurecollection"`) is recased.
- **Incomplete features.** A bare geometry, or a Feature without `geometry` or `properties` (required, even as `null`): wrapped or completed.
- **Coordinates as text.** `"2.17"` becomes `2.17`.
- **Latitude outside ±90.** Swapped back when swapping explains it.
- **Metres, not degrees.** Web Mercator (EPSG:3857) is converted to WGS 84; other projections need exporting again.
- **Broken shapes.** Open rings are closed. Lines under 2 positions, rings under 4 and positions that aren’t numbers can’t be repaired, so those features are removed and named. Extra values after the altitude are only noted.

Warnings are valid GeoJSON that software may still trip over:

- **Winding order.** Rings against the right-hand rule are reversed.
- **A `crs` member.** Dropped, since RFC 7946 removed it. Web Mercator is converted first; a `crs` naming another projection stays, as it’s the only record of what the numbers mean.
- **Longitude past ±180.** Wrapped back onto the map.
- **GeometryCollection.** Split into one Feature per member.
- **Self-intersections.** A bow-tie ring is pointed to, not fixed: only you know the intended shape.
- **Smaller things.** A `bbox` that doesn’t fit (dropped), odd ids, more than 10,000 features.

**Notes change nothing by themselves.** They mention `null` geometries, altitudes and duplicate ids, and offer Round to 6 decimals when there are more than 7.

## Why valid JSON can still be broken GeoJSON
**JSON is only the envelope.** A JSON linter checks brackets and commas; GeoJSON adds rules about what goes inside, and map software needs them to hold.

The three that catch people out most:

- **Longitude first.** `[2.17, 41.38]` is Barcelona; `[41.38, 2.17]` lands in East Africa, and both pass.
- **Degrees in WGS 84.** There is no `crs` any more, so a file in metres can’t say what it is.
- **Closed rings.** Four positions or more, the last equal to the first.

**Will it import into Spatibase?** The validator runs every geometry through the importer’s own code. The importer is kinder than the RFC: it closes rings, wraps longitudes, ignores winding, keeps 2D and rounds to 7 decimals. It skips GeometryCollections, latitudes past ±90 and too-short shapes, and takes up to 10,000 features.

## Validate GeoJSON in code
check-geojson, the successor to Mapbox’s geojsonhint, parses the text and throws a list of problems; geojson-rewind fixes the winding.

```js
import { check, HintError } from '@placemarkio/check-geojson'
import rewind from '@mapbox/geojson-rewind'

try {
  const geojson = check(text) // text: the file's contents as a string
  const fixed = rewind(geojson, false) // false: outer rings counter-clockwise (RFC 7946)
  console.log(JSON.stringify(fixed))
} catch (err) {
  if (!(err instanceof HintError)) throw err
  for (const issue of err.issues) console.log(issue.message)
}
```

**With GDAL,** `ogr2ogr -f GeoJSON -lco RFC7946=YES out.geojson in.geojson` writes WGS 84, counter-clockwise rings and 7 decimals; `-makevalid` (GDAL 3.1+) repairs self-intersections.

**In Python,** shapely’s `shape(geometry).is_valid`, with `explain_validity` and `make_valid` from `shapely.validation`.

**None of them catch** swapped coordinates that stay in range: put the data on a map.

## Frequently asked questions
### Why is my GeoJSON invalid?
Usually a trailing comma, a Feature without properties, coordinates written as strings, a ring that isn’t closed, or latitude before longitude. Paste it above to see which, with the line number.

### What is the right-hand rule in GeoJSON?
Outer rings run counter-clockwise, holes clockwise. RFC 7946 says “should”, and d3-geo expects the opposite, so it’s a warning here; the fix reverses the rings that break it.

### Does GeoJSON use latitude, longitude or longitude, latitude?
Longitude, then latitude: [2.17, 41.38] is Barcelona. Swapped values often stay in range and pass every check, so check the map.

### Should I remove the crs member from GeoJSON?
Yes, once the coordinates are WGS 84 degrees: RFC 7946 removed it in 2016 and most software ignores it. A crs of EPSG:3857 means metres; the validator converts those first.

### How many decimals should GeoJSON coordinates have?
Six, about 10 cm, as RFC 7946 suggests. More only makes the file bigger; Round to 6 decimals trims them and shows the bytes saved.

### Is my GeoJSON sent anywhere when I validate it?
No. Your browser checks it on your device and never uploads it; only the background map tiles load from the internet. Files up to 50 MB work, and a big one takes a few seconds.

## Next step
Turn the fixed file into a live map your team can edit: **Save to Spatibase (free)** on the page saves it to a free Spatibase project (https://app.spatibase.com/signup), your places on a map you can edit and a live GeoJSON address for your site. Or download the fixed GeoJSON and import it by hand (https://spatibase.com/docs/content/import/).
