【发布时间】:2017-02-24 16:18:17
【问题描述】:
我正在尝试通过为给定数组中的每个对象分配一个 id 来重构我的 JSON。该 id 将通过使用现有的键值 (osm_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?