gpt4 book ai didi

jmespath - 如何从父级获取具有字段的所有子元素的列表

转载 作者:行者123 更新时间:2023-12-02 10:53:22 26 4
gpt4 key购买 nike

我有一个字典列表,其中一个字段中包含另一个列表。我想“展平”该列表,因此它为我提供了每个子元素,并将父元素中的一个字段(或某些字段)复制到其中。示例:

源数据:

[
{
"name": "A",
"foo": "x",
"bar": 1,
"subelements": [
{
"baz": "xyz",
"foobar": "abc"
},
{
"baz": "zzz",
"foobar": "def"
}
]
},
{
"name": "B",
"foo": "Y",
"bar": 4,
"subelements": [
{
"baz": "yyy",
"foobar": "aaa"
},
{
"baz": "xxx",
"foobar": "bbb"
},
{
"baz": "www",
"foobar": "bbb"
}
]
}
]

预期结果:

[
{
"baz": "xyz",
"foobar": "abc",
"foo": "x"
},
{
"baz": "zzz",
"foobar": "def",
"foo": "x"
},
{
"baz": "yyy",
"foobar": "aaa",
"foo": "Y"
},
{
"baz": "xxx",
"foobar": "bbb",
"foo": "Y"
},
{
"baz": "www",
"foobar": "bbb",
"foo": "Y"
}
]

最佳答案

如果没有父节点引用,目前无法做到这一点。父节点访问依然是listed as a feature request

关于jmespath - 如何从父级获取具有字段的所有子元素的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52683015/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com