GeoJSON formatting with jq

Having to format some GeoJSON data like so

{
	"type": "FeatureCollection",
	"name": "My Places",
	"crs": {
		"type": "name",
		"properties": {
			"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
		}
	},
	"features": [{
			"type": "Feature",
			"properties": {
				"Name": "Hana Sub",
				"description": null
			},
			"geometry": {
				"type": "Point",
				"coordinates": [-155.995857273402208, 20.765941277181849]
			}
		}, ...
    ]
}

I need the point location as lat/lng and the name so from the above

Name and geometry coordinates

Using jq I can extract the data from the file in a CSVish format with the following bash command.  I have added the tr command to remove some unnecessary text from the results

jq '.features | .[] | .properties.Name + ", " + (.geometry.coordinates[1]|tostring) + ", " + (.geometry.coordinates[0]|tostring)' doc.geojson | tr -d '"' | tr -d ' Sub'

Example results

Hana,20.76594127718185,-155.9958572734022

I could also extract the relevant data as a intermediate JSON format like so

  • name
  • latitude
  • longitude
jq '.features | .[] | {name: .properties.Name, latitude: (.geometry.coordinates[1]|tostring), longitude: (.geometry.coordinates[0]|tostring)}' doc.geojson

Example results

{
  "name": "Mahinahina Sub",
  "latitude": "20.95812321590161",
  "longitude": "-156.6657055616665"
}