我有一个包含多个几何图形的 TopoJSON 文件。看起来像这样:
{
"type": "Topology",
"objects": {
"delegaciones": {
"geometries": [
{
"properties": {
"name": "Tlalpan",
"municip": "012",
"id": "09012",
"state": "09"
}
...
我希望能够从 properties
中获取 id
字段,并将其分配给父级,以便结果是:
{
"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 逐个迭代元素吗?或者我怎样才能做到这一点?
最佳答案
以下内容按要求添加“id”属性:
.objects.delegaciones.geometries[] |= (.id = .properties.id)
关于javascript - 使用jq将子属性分配给父字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33525267/