
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
geojson-parser
Advanced tools
You can specify a callback function as an option third parameter.
GeoJSONParser.parse(data, {Point: ['lat', 'lng']}, function(geojson){
console.log(JSON.stringify(geojson));
});
Depending on which makes more sense for the data that is being parsed, either specify an array of attributes to include or exclude in properties for each feature. If neither include nor exclude is set, all the attributes (besides the attributes containing the geometry data) will be added to feature properties.
include - Array of attributes to include in properties for each feature. All other fields will be ignored.exclude - Array of attributes that shouldn't be included in feature properties. All other attributes will be added (besides geometry attributes)The geometry parameters specify which attribute(s) contain(s) the geographic/geometric data. A geometry parameter must be specified for each type of geometry object that is present in the data that is being parsed. For example, if the data contains both points and polygons, specify both the Point and Polygon parameters. Note that geometry parameters must be in proper case. See the GeoJSON spec for details on each geometry type. The structure of the geometry parameter is:
ParameterName: 'attributeName'
Except for Point, which can be specified with a field name or an array of field names, i.e:
data = [{ name: 'location', x: 34, y: 85 }];
GeoJSON.parse(data, {Point: ['lat', 'lng']});
or
data = [{ name: 'location', coords: [85, 34] }];
GeoJSON.parse(data, {Point: 'coords'});
The valid geometry types are
PointMultiPointLineStringMultiLineStringPolygonMultiPolygonTo parse already encoded GeoJSON use
GeoJSON
var data = [{name: 'Location A', geo: {"type": "Point", "coordinates": [125.6, 10.1]}}];
GeoJSON.parse(data, {GeoJSON: 'geo'});
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
},
"properties": {
"name": "Location A"
}
}]
}
geojson.js also supports the optional GeoJSON properties bbox and crs.
crs - An object identifying a coordinate reference system. More informationbbox - A bounding box for the feature collection. An array with the following format: [y1, x1, y2, x2]. More informationYou can add arbitrary properties to features using the extra param. The value for extra must be an object. For example, using the original sample data:
GeoJSON.parse(data, {
Point: ['lat', 'lng'],
extra: {
style: {
"color": "#ff7800",
"weight": 5,
"opacity": 0.65
}
}
});
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [-75.343, 39.984]},
"properties": {
"name": "Location A",
"category": "Store",
"style": {
"color": "#ff7800",
"weight": 5,
"opacity": 0.65
}
}
},
...
}
You can also add dataset properties using the extraGlobal param. The value for extraGlobal must be an object.
GeoJSON.parse(data, {
Point: ['lat', 'lng'],
extraGlobal: {
'Creator': 'Mr. Example',
'records': data.length,
'summary': 'A few example points'
}
});
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [-75.343, 39.984]},
"properties": {
"name": "Location A"
}
},
...
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [ -75.534, 39.123]},
"properties": {
"name": "Location C"
}
}
],
"properties": {
"Creator": "Mr. Example",
"records": 2,
"summary": "A few example points"
}
}
For node, $ npm test.
Licensed under the MIT License. See LICENSE for details.
FAQs
Parse JSON to GeoJSON
We found that geojson-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.