颠簸变换数组数据
Jolt transformation array data
我想像这样使用 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"
}
]
}
非常感谢一些说明
您可以使用 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": ""
}
}
}
}
]
我想像这样使用 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"
}
]
}
非常感谢一些说明
您可以使用 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": ""
}
}
}
}
]