我有一个包含多个几何的TopoJSON文件。它看起来像这样:
{
"type": "Topology",
"objects": {
"delegaciones": {
"geometries": [
{
"properties": {
"name": "Tlalpan",
"municip": "012",
"id": "09012",
"state": "09"
}
...
我希望能够从id
获取properties
字段,并将其分配给父级,以便结果为:
{
"type": "Topology",
"objects": {
"delegaciones": {
"geometries": [
{
"id": "09012",
"properties": {
"name": "Tlalpan",
"municip": "012",
"id": "09012", // <-- It's okay if it's removed or not
"state": "09"
}
...
我在jq上尝试了以下任务,但它不正确:
jq '.objects.delegaciones.geometries[].id = .objects.delegaciones.geometries[].properties.id' topo_df.json
任何人都知道如何逐个制作jq迭代元素?或者我如何才能使这项工作?
答案 0 :(得分:2)
以下添加&#34; id&#34;所要求的财产:
.objects.delegaciones.geometries[] |= (.id = .properties.id)