我想使用JOLT来转换JSON,如下所示:
Input: {
"array": [
"1","2","3","4"
],
"array2": [
{
"something": "123",
"something1": "Plane"
},
{
"something3": "567",
"something4": "Car"
}
]
}在下面的格式中,正如您从输出中看到的,我需要来自两个数组的数据来匹配确切的参数名称,而不是像第一个那样为空,或者像第二个那样存在的参数名称。
Output: {
"one_array": [
{
"code": "1",
"description": "",
},
{
"code": "2",
"description": "",
},
{
"code": "3",
"description": "",
},
{
"code": "4",
"description": "",
}
], "other_array": [
{
"id": "123",
"type": "Plane"
},
{
"id": "567",
"type": "Car"
}
]
}有些澄清是非常感谢的。
发布于 2021-02-02 19:20:12
您可以使用2个shift操作和default操作来实现此目的,如下所示。
[
{
"operation": "shift",
"spec": {
"array": {
"*": {
"@": "one_array[&].id"
}
},
"array2": {
"*": {
"*": {
"@": "tmp_array[&2]"
}
}
}
}
},
{
"operation": "shift",
"spec": {
"one_array": "one_array",
"tmp_array": {
"*": {
"0": "other_array[&1].id",
"1": "other_array[&1].type"
}
}
}
},
{
"operation": "default",
"spec": {
"one_array[]": {
"*": {
"description": ""
}
}
}
}
]https://stackoverflow.com/questions/66000506
复制相似问题