I am trying to restructure my JSON by assigning an id to each object in a given array. This id would be created by using an existing key value (osm_id).
This is my input:
[
{
"geometry" : {
"coordinates" : [ -0.7118478, 51.0930284 ],
"type" : "Point"
},
"properties" : {
"osm_id" : "262661",
"religion" : "christian"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [ -0.7207513, 51.0897118 ],
"type" : "Point"
},
"properties" : {
"denomination" : "catholic",
"osm_id" : "262662",
"religion" : "christian"
},
"type" : "Feature"
}
]
This is my desired output:
[
"262661": {
"geometry": {
"coordinates": [
-0.7118478,
51.0930284
],
"type": "Point"
},
"properties": {
"osm_id": "262661",
"religion": "christian"
},
"type": "Feature"
},
"262662": {
"geometry": {
"coordinates": [
-0.7207513,
51.0897118
],
"type": "Point"
},
"properties": {
"denomination": "catholic",
"osm_id": "262662",
"religion": "christian"
},
"type": "Feature"
}
]
I've been trying to work with jq to update the data, but I can't figure out how to assign that top level id. So far I have
.[] |= {geometry, properties, type}
but anything further results in errors.
I appreciate any help or input.