Map data·5 min read
GeoJSON vs Shapefile vs KML: Which File Should You Send?
GeoJSON is one text file you can open in Notepad, a shapefile is a set of binary files you cannot, and KML is XML that also knows what color a state should be. Send GeoJSON when a script or a person will read it, a shapefile when a GIS will open it, KML when the destination is Google Earth — and stop using file size to decide.

The short answer, one line per format
The format is chosen by the software on the other end, not by the specification:
- GeoJSON — one UTF-8 text file, longitude and latitude only, attributes as a JSON object per feature. Send it when a script, a web map, or a human with a text editor will read it.
- Shapefile — three or four binary files that share one basename. Send it when the recipient opens ArcGIS or QGIS for a living; it is still the format nobody refuses.
- KML — one XML file, or a zipped
.kmz. Send it when the destination is Google Earth, because the styling is the only thing it does better.
All three can describe the identical 56 state polygons. Only one of them can be opened, read, and diffed on a laptop with no GIS installed, and that is GeoJSON.
GeoJSON vs shapefile vs KML, side by side
| GeoJSON | Shapefile | KML | |
|---|---|---|---|
| Container | One .geojson text file | .shp + .shx + .dbf, plus .prj | One .kml, or a zipped .kmz |
| Geometry | Nested arrays of [lon, lat] | Variable-length records in .shp | <coordinates> text: lon,lat,alt |
| Attributes | properties object, real types | .dbf table, 10-character names, no NULL | <ExtendedData>, every value a string |
| Coordinate system | WGS84 only, required by the spec | Anything, declared in .prj | WGS84 only, required by the spec |
| Styling | None at all | None at all | <Style>: fill, outline, icon, balloon |
| Readable in a text editor | Yes | No | Yes, if XML does not bother you |
| Standard | RFC 7946, 2016 | Esri, 1998 (open spec) | OGC KML, 2008 |
Two rows settle most arguments. Coordinate system: a shapefile can hold State Plane feet or Web Mercator meters; GeoJSON and KML cannot hold anything but WGS84 decimal degrees, so a projected layer has to be reprojected before it can be written as either. Styling: KML is the only one of the three that knows a polygon is supposed to be dark red.
Read the first 120 characters of a real file
This is the opening of a national state boundary file, byte for byte, nothing removed:
from pathlib import Path
text = Path("us_state.geojson").read_text(encoding="utf-8")
print(text[:120])
print(text.count("\n"), "newlines")
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"STATEFP":"21","STATENS":"01779786","GEOIDFQ":"0
0 newlines
Fifty-six states and territories, 2,296,016 bytes, and not one newline in the file. read_text() gives back a string of 2.3 million characters because every character in it is ASCII. Nothing in the file is addressed by line number, so every editor that opens it will pause, and every reader will spend its time parsing rather than seeking.
That is a real difference from the binary format, not a cosmetic one. A shapefile starts with a 100-byte header that states the file length, so a truncated download can be detected before reading a single shape. GeoJSON has no header, no magic number, and no length field: a truncated file is simply invalid JSON, and the parser's complaint will point at whatever character it happened to be on. Truncation is easier to diagnose in the binary format, and easier to work around in the text one.
The rules that make a file valid GeoJSON are short, and RFC 7946 is worth reading once:
- Coordinates are WGS84 decimal degrees, longitude first. A shapefile carries its own projection; GeoJSON cannot, so
-122.4, 37.8is the only shape a coordinate is allowed to take. - The
crsmember is gone. Files from older exporters still carry"crs": {"type": "name", ...}and readers ignore it — reproject before export instead of hoping. - An exterior ring runs counterclockwise, holes run clockwise. Get this backwards and a fill test will think the state is the hole.
- Right-hand rule aside, the whole thing is one JSON object.
typeisFeatureCollection, and every feature haspropertiesandgeometry, in that order by convention.
What KML does that the other two cannot
KML's <Placemark> is a place, not a row. It has a <name> that shows in the Google Earth sidebar, a <description> that opens as a balloon on click, and a <Style> that can set fill color, outline width, and label size. Folders group placemarks into a tree you can check on and off. None of that exists in GeoJSON — a web map decides styling in JavaScript, and a shapefile gets its colors from a separate .lyr or QML file that travels beside it if you remember to send it.
Two details trip people up when they hand-write or patch a KML:
- Coordinates are
lon,lat,alttriples separated by whitespace inside one<coordinates>element, not a nested array. That is why a KML of the county layer is a single very long line of numbers. - A
.kmzis a zip archive containingdoc.kmland any icons. It is not a different format, and renaming a.kmzto.kmlgives you a file no parser will read.
KML is also the format that survives a round trip through Google Earth's "Save place as" without losing its colors, which is exactly the case where its verbosity pays for itself.
Size on disk, measured on the same 56 polygons
Everyone assumes KML is the fat one. Measured on the state layer above, it is the smallest of the three:
| Rendering of the same 56 polygons | Bytes | Gzipped |
|---|---|---|
| GeoJSON as published, 13 decimal places | 2,296,016 | 829,050 |
| GeoJSON rounded to 5 decimals | 1,948,909 | 634,705 |
| KML, 5 decimals, geometry only | 1,784,378 | 620,154 |
The layer holds 91,888 vertices, so the raw file spends 25 bytes per vertex. Rounding every coordinate to five decimal places — about 1.1 meters, far below the width of a state line on a slide — removes 347,107 bytes, 15 percent, without moving a boundary anywhere a reader could see. That is a bigger effect than the choice of format.
import gzip, json
from pathlib import Path
src = Path("us_state.geojson")
data = json.loads(src.read_text(encoding="utf-8"))
def r5(geom):
def walk(c):
return [round(c[0], 5), round(c[1], 5)] if isinstance(c[0], (int, float)) else [walk(x) for x in c]
return {"type": geom["type"], "coordinates": walk(geom["coordinates"])}
compact = {"type": "FeatureCollection",
"features": [{"type": "Feature",
"properties": f["properties"],
"geometry": r5(f["geometry"])} for f in data["features"]]}
raw = json.dumps(compact, separators=(",", ":")).encode("utf-8")
print(src.stat().st_size, len(raw), len(gzip.compress(raw, 9)))
# 2296016 1948909 634705
KML compresses better than GeoJSON — 620,154 bytes against 634,705 — because XML repeats the same tag names tens of thousands of times and repetition is what gzip eats. Over the wire, with compression on, the two formats land within 2 percent of each other. Size stopped being a reason to pick one years ago; what is left is which software can open it.
Converting without losing the GEOID
GDAL does all six conversions and is one install away (brew install gdal, or the OSGeo4W installer on Windows):
ogr2ogr -f GeoJSON states.geojson us_state.shp -lco RFC7946=YES
ogr2ogr -f KML states.kml us_state.shp
ogr2ogr -f "ESRI Shapefile" roundtrip states.geojson
The RFC7946=YES flag matters. Without it, GDAL writes the deprecated crs member and leaves coordinates in whatever projection the source used; with it, you get WGS84 and a file that any web map will accept without complaint.
The lossy step is never the geometry, it is the attribute table:
| Moving from → to | What happens to GEOID |
|---|---|
| Shapefile → GeoJSON | Text stays text. 01001 survives intact |
| GeoJSON → shapefile | Field names truncate at 10 characters, values survive |
| Anything → KML | Every value becomes a string; numbers come back as text |
| Either → spreadsheet → back | Leading zeros die, and 01001 becomes 1001 |
A KML round trip turns ALAND from an integer into the string "102267794436", and nothing in the file records that it used to be a number. If the attributes are going to be joined to anything downstream, convert to GeoJSON or shapefile and leave KML for the map you are about to look at. What the codes themselves mean is the companion piece to this one; the shapefile breakdown explains why its table has those limits in the first place.
Why none of the three opens in PowerPoint
There is no import path from any of these formats into a slide. PowerPoint will take an SVG, and an SVG has no attribute table, so a boundary file has to be converted to native shapes with the names attached before a deck can use it — one shape per polygon, NAME from the properties beside it. That conversion is the whole product: the state map is 56 editable shapes, and the county map is the same idea at 3,235.

.prj left to lose and no attribute table to join.Is GeoJSON better than a shapefile?
Can I just rename a .kml to .kmz?
Does GeoJSON support projection?
Which format should I send for a slide deck?
Skip the conversion
Every state and county arrives as an editable polygon with its name and code already attached — no GDAL, no reprojection, no missing .prj.
See the state mapQuestions
Is GeoJSON better than a shapefile?
Can I just rename a .kml to .kmz?
Does GeoJSON support projection?
Which format should I send for a slide deck?
Written in-house. Boundary counts are checked against the published files, and every figure on this page can be reproduced from the source named in it.