How to Convert GeoJSON to KML

Published · Last updated

Exchange delivery locations, routes and geographic areas between GeoJSON-based software, GIS and applications that read KML.

Try it now: GeoJSON, TopoJSON, KML and Shapefile converter

Before you start

KML is an XML format used by Google Earth and other applications that read placemarks, lines and polygons. GeoJSON is a JSON format widely used in web mapping. Both can describe the same points, lines and polygons, so converting between them mostly changes how the geometry and attributes are written.

This can help when a transport or logistics system exchanges delivery locations, route geometries or service-area boundaries with a mapping application that accepts KML. It changes the document format; it does not calculate a route or make a service area from the data.

Check the GeoJSON first. A conversion cannot succeed if the source is not valid JSON, so run it through the GeoJSON validator if you are unsure. If it fails, see how to fix invalid GeoJSON.

Worked example

This GeoJSON Feature describes a single point in Copenhagen. Longitude comes first, then latitude:

{
  "type": "Feature",
  "properties": { "name": "Copenhagen" },
  "geometry": { "type": "Point", "coordinates": [12.5, 55.7] }
}

In KML, a point is written as a Placemark containing a Point, and coordinates are also written longitude,latitude (optionally followed by altitude), separated by commas with no spaces. A KML result for this feature therefore contains the same position as:

<Placemark>
  <name>Copenhagen</name>
  <Point>
    <coordinates>12.5,55.7</coordinates>
  </Point>
</Placemark>

The exact elements, ordering and styling in the converter's output are produced by the conversion service and can differ from this illustration. What matters is that the position is unchanged and still reads 12.5,55.7, not 55.7,12.5.

Step-by-step conversion

  1. Open the GeoJSON, TopoJSON, KML and Shapefile converter.
  2. Set From to GeoJSON and To to KML. The two formats must differ.
  3. Paste the GeoJSON into the input box.
  4. Press Convert.
  5. Review the KML in the result box, then use Download result to save it.
  6. Open the saved file in the application where you will use it and check that features appear in the right place.

Input conventions

  • Coordinate order. GeoJSON positions are [longitude, latitude]. KML coordinates are longitude,latitude. Neither is latitude first.
  • Coordinate system. GeoJSON positions are WGS84 longitude and latitude. Projected coordinates such as UTM eastings and northings are not valid GeoJSON positions.
  • Structure. Package data as a Feature or a FeatureCollection, and put several features in one FeatureCollection.
  • Properties. Feature properties are attributes such as name. How they appear in KML is determined by the conversion service, so inspect the output for the attributes you need.

Common errors

  • The source format selection does not match the data. Pasting GeoJSON while From is set to TopoJSON or KML produces a conversion error. Check both selectors.
  • Invalid JSON. Trailing commas, missing quotes or unbalanced brackets stop the conversion before any GeoJSON logic applies.
  • Features land in the wrong place. Swapped latitude and longitude is the most common cause. A point meant for Copenhagen written as [55.7, 12.5] is a valid position elsewhere.
  • Missing attributes in the KML. Confirm the properties exist in the source and look for them in the converted output before relying on them elsewhere.

To convert in the other direction, set From to KML and To to GeoJSON in the same converter.

Applications can also automate supported document conversions through the Geospatial Toolbox API. See the API reference for supported formats and request details. For a comparison of geographic data formats, read GeoJSON vs TopoJSON.

Tools used in this guide

Related guides

Browse all technical guides