我试图通过为给定数组中的每个对象分配一个id来重构我的JSON。将使用现有键值(osm_id)创建此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}
但任何进一步导致错误。
感谢任何帮助或意见。
答案 0 :(得分:0)
我昨天刚回答了类似的问题。
Bind
请注意,当它应该是一个对象(对于键)时,你想要的输出是一个数组[]。