About GeoJSON files
GeoJSON (RFC 7946) describes points, lines and polygons as JSON, with coordinates in longitude, latitude order. Map libraries such as Leaflet, Mapbox GL and OpenLayers load it directly, and GitHub renders .geojson files as maps.
File signature
GEOJSON has no fixed signature: it is data without a magic number, so validate uploads by parsing the content rather than by checking bytes.
Serve .geojson with the right Content-Type
Content-Type: application/geo+json
application/geo+json geojson;
AddType application/geo+json .geojson
@geojson path *.geojson
header @geojson Content-Type "application/geo+json"
curl -sI https://example.com/file.geojson | grep -i '^content-type'
# Content-Type: application/geo+json
Set the type in code
res.set('Content-Type', 'application/geo+json');
// Or make the browser download it:
res.attachment('file.geojson');
import mimetypes
mimetypes.add_type('application/geo+json', '.geojson') # if your system doesn't know it
mimetypes.guess_type('file.geojson')[0] # 'application/geo+json'
mime.AddExtensionType(".geojson", "application/geo+json")
w.Header().Set("Content-Type", "application/geo+json")
Accept .geojson uploads
<input type="file" accept=".geojson,application/geo+json">
The accept attribute only filters the file picker; users can still choose another file. Listing the
extension as well as the type matters, because operating systems don’t always report the type you expect.
Related types
More data and text
.txt , .tsv , .md , .ndjson , .xml , .yaml , .ics , .sql . Look up any extension or type with the MIME type lookup.
Sources
Spotted a mistake? Email hello@devtoolsmith.com and we’ll fix it.
Frequently asked questions
What is the MIME type for .geojson files?
application/geo+json. The full header is "Content-Type: application/geo+json".
Why does my server send the wrong Content-Type for .geojson?
Web servers pick the type from the file extension using a table (mime.types in nginx and Apache). If .geojson is missing from that table, they send a default such as application/octet-stream or text/plain. Add the mapping as shown on this page, then check the response with "curl -sI".
How can I check that a file really is GEOJSON?
GEOJSON has no fixed file signature, so the extension and content are all you have. Check that the content is what you expect, for example by parsing it, before trusting an upload.