使用JOLT转换重命名嵌套数组中的字段 [英] Rename fields in nested arrays using JOLT transformation
本文介绍了使用JOLT转换重命名嵌套数组中的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用JOLT转换库重命名嵌套在另一个数组中的数组中的字段. 1.要重命名的字段是数组中的顶级字段 2.两个要重命名的字段都在嵌套数组
I want to rename fields in an array nested in an another array using JOLT transformation library. 1. One field to rename is a top level field in an array 2. Two fields to rename are inside a nested array
我尝试使用通配符,但是它们没有给我预期的输出.我正在使用JOLT 0.0.22版本.
I have tried using wildcards but they are not giving me expected output. I am using JOLT 0.0.22 version.
输入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"
}
}
}
}
}
}
]
这篇关于使用JOLT转换重命名嵌套数组中的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文