A library that contains methods to convert KML to JSON and JSON to KML.
MIT License
KML to JSON is a library made with Typescript that contains tools for KML files conversion.
First, be sure to have Node.js installed.
Then, install it by running:
$ npm install --save kml-to-json
The library has 4 functions that may be used. They are:
It converts a KML file to a JSON object, keeping all tags names, attributes, texts and children.
Receives a file of the type application/vnd.google-earth.kml+xml
or with the extension kml
.
It throws an error when the file type is incorrect.
Returns an object containing all KML data with this structure.
kmlToJson(file: File): Object
It converts a KML file to a JSON string, representing all tags names, attributes, texts and children.
Receives a file of the type application/vnd.google-earth.kml+xml
or with the extension kml
.
It throws an error when the file type is incorrect.
Returns a string representing the KML data with this structure.
kmlToJsonString(file: File): string
It converts a JSON object or string to a KML file.
Receives an object or string with this structure.
It throws an error when the given parameter is not from type object or string.
Returns a blob that represents the KML file. Its type is application/vnd.google-earth.kml+xml
.
jsonToKml(json: Object | string): Blob
It converts a JSON object or string to a structured KML string.
Receives an object or string with this structure.
It throws an error when the given parameter is not from type object or string.
Returns a string that represents the KML string structure.
jsonToKmlString(json: Object | string): string
{
"test-tag": {
"attributes": {
"attr1": null,
"attr2": null,
"class": "class-1",
"id": "test-tag"
},
"children": {
"child1": {
"attributes": {},
"order": 0,
"children": {
"child3": {
"attributes": {
"attr3": null
},
"children": {
"text0": {
"data": "Some text...",
"order": 0
}
},
"order": 0,
}
}
},
"child2": {
"attributes": {},
"order": 1,
"children": {}
}
},
"order": 0,
}
}
The KmlToJson project is licensed under the MIT license.