gpt4 book ai didi

json - 使用 JOLT 转换重命名嵌套数组中的字段

转载 作者:行者123 更新时间:2023-12-05 08:42:36 24 4
gpt4 key购买 nike

我想使用 JOLT 转换库重命名嵌套在另一个数组中的数组中的字段。1.要重命名的一个字段是数组中的顶级字段2.要重命名的两个字段在嵌套数组中

我试过使用通配符,但它们没有给我预期的输出。我使用的是 JOLT 0.0.22 版本。

输入JSON:

{
"country": "usa",
"state": [
{
"stateName": "TX",
"location": "south",
"cities": [
{
"name": "Austin",
"pop": "1M"
},
{
"name": "Dallas",
"pop": "2M"
}
]
},
{
"stateName": "CA",
"location": "west",
"cities": [
{
"name": "SanFran",
"pop": "3M"
},
{
"name": "LosAngeles",
"pop": "4M"
}
]
}
]
}

预期输出:

{
"country": "usa",
"state": [
{
"stateName": "TX",
"locatedIn": "south", // name change here
"cities": [
{
"cityname": "Austin", // name change here
"citypopulation": "1M" // name change here
},
{
"cityname": "Dallas",
"citypopulation": "2M"
}
]
},
{
"stateName": "CA",
"locatedIn": "west",
"cities": [
{
"cityname": "SanFran",
"pop": "3M"
},
{
"cityname": "LosAngeles",
"citypopulation": "4M"
}
]
}
]
}

最佳答案

规范

[
{
"operation": "shift",
"spec": {
"country": "country",
"state": {
"*": { // state array index
"stateName": "state[&1].stateName",
"location": "state[&1].location",
"cities": {
"*": { // city array index
"name": "state[&3].cities[&1].cityname",
"pop": "state[&3].cities[&1].citypopualtion"
}
}
}
}
}
}
]

关于json - 使用 JOLT 转换重命名嵌套数组中的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39585360/

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