【发布时间】:2017-02-13 23:12:40
【问题描述】:
这是我的数据结构:
[
{
"name": "name1",
"organizations": [
{
"name": "name2",
"spaces": [
{
"name": "name3",
"otherkey":"otherval"
},
{
"name": "name4",
"otherkey":"otherval"
}
]
}
]
},
{
"name": "name21",
"organizations": [
{
"name": "name22",
"spaces": [
{
"name": "name23",
"otherkey":"otherval"
},
{
"name": "name24",
"otherkey":"otherval"
}
]
}
]
}
]
我只想保留 name=name1,删除 name=name4 的嵌套数组对象,并希望保持对象的其余部分完好无损。我尝试使用 map(select) 但这只会给我完整的对象。是否可以在特定子数组上使用 del 并保持其余部分不变?
结果应该如下。此外,我想避免枚举所有属性以保留在外部对象上:
[
{
"name": "name1",
"organizations": [
{
"name": "name2",
"spaces": [
{
"name": "name3",
"otherkey":"otherval"
}
]
}
]
}
]
有什么想法吗?谢谢!
【问题讨论】: