-3
我想通過給給定數組中的每個對象分配一個id來重構我的JSON。該id將通過使用現有的鍵值(osm_id)來創建。使用jq從JSON鍵值創建對象ID
這是我輸入:
[
{
"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"
}
]
這是我想要的輸出:
[
"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"
}
]
我一直在試圖與JQ一起更新的數據,但我想不出如何分配頂級ID。到目前爲止,我有
.[] |= {geometry, properties, type}
但是任何進一步的結果都會導致錯誤。
我欣賞任何幫助或輸入。
過得好是被添加到每個對象osm_id? –