Why convert KML to GeoJSON
KML is the format of Google Earth. If you draw a route in Google My Maps, mark places in Google Earth, or receive a map from a client who uses Google tools, you will probably get a .kml file. KML is an XML format. It stores places, lines and areas, but it also stores a lot of things that are made for Google Earth: icons, colors, folders, camera positions, tours and links to other files.
GeoJSON is simpler. It is one JSON file with a list of features, and each feature has a geometry and a set of properties. Almost every web map library reads it directly: Leaflet, Mapbox GL JS, MapLibre, OpenLayers and deck.gl. GitHub also draws a .geojson file as a map. A KML file does not work in most of these places without a conversion step.
This tool does that step for you. You choose a KML file, the tool reads every placemark, and you see the result on a map before you download anything. You can decide if the KML styles stay in the output, if the altitude values stay, and if the folder name is added to each feature. The work happens in your browser, so your file stays on your device.
The KML format: history and structure
KML stands for Keyhole Markup Language. It was created by Keyhole, Inc., the company that built the Earth Viewer program, and Google bought Keyhole in 2004. That program became Google Earth. In April 2008 the Open Geospatial Consortium (OGC) adopted KML 2.2 as an open standard, and version 2.3 followed in 2015. Today KML is used far beyond Google Earth, in field surveys, drone flight plans, telecom maps and public data downloads.
A KML file has a <kml> root element. Inside it, a <Document> or <Folder> groups the content, and each place is a <Placemark>. A placemark has a <name>, an optional <description>, and one geometry: <Point>, <LineString>, <Polygon>, or a <MultiGeometry> that holds several. Coordinates are written as longitude,latitude,altitude, separated by commas, with a space between points. The order is longitude first, which is the same as GeoJSON.
KML also has many parts that GeoJSON does not have. A <Style> block sets line color, line width, fill color and the icon. Colors are written in aabbggrr order (alpha, blue, green, red), which is the reverse of the web color #rrggbb. <ExtendedData> stores your own attribute fields. Google added a gx:Track element for GPS tracks with a time stamp for every point. Other parts, like <NetworkLink>, <GroundOverlay> and <gx:Tour>, point to data on the web or to images.
The big difference is the idea behind each format. KML describes how a map should look in Google Earth. GeoJSON describes only the data: shapes and attributes. Because of this, a KML to GeoJSON converter has to make choices. Folders do not exist in GeoJSON, so the folder name can become a property. Styles do not exist in the standard either, so they become plain properties such as stroke and fill. Anything that is not geographic data, like tours and camera views, has no place in the output.
Step-by-step guide: how to convert KML to GeoJSON

Click "Choose File" and select your .kml file, or click "Try sample" to load a small file with three folders. If your file is a .kmz, unzip it first and use the doc.kml file inside.

The file is read at once and the placemarks appear on the map as a gray "Source KML" layer. The Layers panel shows how many features were found. Check that the right data is there.

Pick your options. Keep or remove the KML styles, keep or remove the altitude, add the folder name to each feature, and turn pretty printing on or off. The defaults are good for most files.

Click "Convert to GeoJSON". An orange "Converted GeoJSON" layer appears on top of the source, and a summary shows the feature count, the geometry types, the bounding box, the attribute columns and the file size. Click a feature to see its name. Turn on "Show basemap" if you want street map context.

Click "Download converted.geojson" to save the file, or use "Copy GeoJSON" to put the text on your clipboard and paste it into geojson.io, a code editor or a GitHub file.
Six real-world use cases
Where a KML to GeoJSON conversion comes up in daily work.
- Putting a Google My Maps map on your website. My Maps exports KML, but Leaflet and Mapbox GL JS read GeoJSON. Convert the file once, host the
.geojson, and your own web map can show the same places without an embed from Google. - Using Google Earth drawings in QGIS or a database. Planners often sketch sites and routes in Google Earth. GeoJSON opens in QGIS, PostGIS and almost every GIS tool, so it is a simple way to move those drawings into real analysis.
- Sharing a map in a GitHub repository. GitHub draws
.geojsonfiles as an interactive map right in the repository. It does not draw.kmlfiles. Convert the file before you commit it and your team can see the map without any software. - Cleaning field survey data. Survey apps and GPS devices often export KML with long style blocks and extra fields. Turn off the style option to get a small GeoJSON file that only holds names, attributes and shapes.
- Sending data to a web API. Many mapping and geocoding APIs accept GeoJSON in a request body and do not accept KML. A converted file can go straight into an upload or a POST request.
- Checking what is inside a KML file. Someone sent you a
.kmland you want to know what it holds. Convert it, look at the attribute columns and the geometry types in the summary, and see all the shapes on a map in a few seconds.
The conversion algorithm, step by step
Converting KML to GeoJSON is a short chain of well-defined steps. Here is what happens to your file, in order.
1. Read the XML and check the root element
The file is read as text and parsed into an XML document with the browser's own DOMParser. If the parser reports an error, or if the root element is not <kml>, the tool stops and shows a read error. This catches HTML pages, broken downloads and files with a wrong extension.
2. Find every Placemark
The converter walks through the document from top to bottom. Every <Folder> opens a new group, and every <Placemark> becomes one GeoJSON Feature. This is how a single placemark is mapped:
<Placemark> { "type": "Feature",
<name>Eiffel Tower</name> "properties": { "name": "Eiffel Tower" },
<Point> "geometry": {
<coordinates> "type": "Point",
2.2945,48.8584,35 "coordinates": [2.2945, 48.8584, 35]
</coordinates> }
</Point> }
</Placemark>The name, the description and all ExtendedData fields go into properties. The <Style> and <StyleMap> blocks of the document are read first, so a placemark that points to #landmarkStyle with styleUrl gets the colors from that style.
3. Turn KML geometry into GeoJSON geometry
Point becomes Point, and LineString becomes LineString. For a Polygon, the outerBoundaryIs ring is written first, and every innerBoundaryIs ring follows as a hole. A MultiGeometry becomes a MultiPoint, MultiLineString or MultiPolygon when all parts have the same type, and a GeometryCollection when the types are mixed. A gx:Track becomes a LineString, and its time stamps are kept in coordinateProperties. Each coordinate string lon,lat,alt is split on commas and changed to numbers in the same order.
4. Apply your options and write the file
Now the options are applied. If you turned off styles, every property that starts with stroke, fill, icon or label, plus styleUrl, is removed. If you turned off altitude, the third number of each coordinate is dropped. If you turned on folder names, the folder path is written to a folder property. Features without any geometry are skipped and counted.
At the end, all features are put into one FeatureCollection and written out with JSON.stringify. Pretty printing adds two spaces of indentation, which is easy to read but makes the file larger. The same KML file and the same options always give the same output.
The GIS tools behind KML conversion
A converter is only as good as the parser under it. These are the tools that do this work, in this page and elsewhere.
- @tmcw/togeojson: The engine of this page. It is a small JavaScript library by Tom MacWright that turns a KML, GPX or TCX document into GeoJSON. It also reads styles and extended data, and it exposes the folder structure that this tool uses for the folder option.
- GDAL / OGR (ogr2ogr): The C++ library under most desktop and server GIS software. The command
ogr2ogr -f GeoJSON output.geojson input.kmlis the standard way to convert from the command line. It reads each KML folder as a separate layer, which is a different approach from the single list used here. - QGIS: The free desktop GIS opens a KML file as a layer, and "Export" then "Save Features As" writes GeoJSON. It uses GDAL inside, and it is a good choice when you also want to change the data.
- geojson.io: A web editor that can import a KML file and show it as GeoJSON in a text pane. It is handy for quick edits after the conversion, and you can paste the output of this tool straight into it.
- GeoPandas and Fiona: In Python,
geopandas.read_file("file.kml", driver="KML")reads a KML file after you enable the KML driver, andto_file("out.geojson", driver="GeoJSON")writes the result. This is a common route inside data pipelines.
All of these tools follow the same two standards, so the shapes they produce should match. The difference is where the work runs. GDAL, QGIS and Python need an installation, while this converter runs in the browser tab you already have open, with no installation and no upload.
Technical questions and answers
Ten common questions about how to convert KML to GeoJSON, with direct answers.
1. How do I convert KML to GeoJSON?
Choose your .kml file in this converter, check the preview on the map, and click "Convert to GeoJSON". Then click "Download converted.geojson". The file is read and converted in your browser, so it takes a few seconds even for large files.
2. How do I get a KML file from Google Earth or Google My Maps?
In Google My Maps, open the menu next to the map title, choose "Export to KML/KMZ", and tick "Export to a .KML file instead of .KMZ". In Google Earth Pro, right-click a place or folder in the sidebar, choose "Save Place As", and pick the KML type. Then use that file here.
3. Is this converter free, and is there a file size limit?
It is free and needs no sign-up. There is no fixed size limit. A very large file takes longer because your own device does all the work, and the speed depends on your browser and your memory.
4. Is my KML file uploaded to a server?
No. The file is read with the browser, parsed with a JavaScript library, and the GeoJSON is built in memory. Your data never leaves your device, which matters if the file holds private sites or customer data.
5. What happens to the colors and icons from KML?
With "Keep KML style properties" on, the tool copies them into each feature as simple properties such as stroke, stroke-width, stroke-opacity, fill and fill-opacity. KML colors in aabbggrr order are changed to normal #rrggbb colors, and the opacity is stored on its own. Turn the option off to get a file without any style data.
6. Are names, descriptions and custom attributes kept?
Yes. The placemark name and description become properties with the same names. Every field in ExtendedData (both Data and SchemaData fields) is also added as a property, so your own attribute columns are in the output.
7. What happens to KML folders?
GeoJSON has no folders, so the structure is flattened into one list of features. If you turn on "Add the folder name as a property", each feature gets a folder property with its folder path, for example Landmarks or Trip / Day 1. You can filter by it later.
8. Can I convert a KMZ file?
A KMZ file is a zip archive, and the main file inside is usually named doc.kml. Rename the KMZ to .zip, unzip it, and choose the doc.kml file here. The images inside the KMZ are not needed for the conversion.
9. What about altitude and the coordinate system?
KML always uses WGS84 longitude and latitude, which is also what GeoJSON requires, so no reprojection is needed. Altitude values are kept as the third number of each coordinate. If you do not want them, turn off "Keep altitude values" and every coordinate becomes a plain longitude and latitude pair.
10. Why do I see fewer features than I expected, or an error?
Items that have no geometry are skipped, for example a NetworkLink that only points to another file, or a placemark with only a name. The result panel tells you how many were skipped. If you get a read error, the file is probably not valid XML, or it is not KML. Open it in a text editor and check that it starts with a <kml> element.
The conversion runs entirely in your browser using @tmcw/togeojson. No file is ever uploaded to a server. Map tiles © OpenStreetMap contributors, drawn with Protomaps (hosted by KONAKTIVE), with CARTO as the fallback. KML reading: @tmcw/togeojson. Map rendering: Leaflet.

Comments
Questions, tips or feedback about this tool? Share them below. Every comment is checked before it appears.
Leave a comment