将一个数组移动到另一个数组中定义的json对象中-JOLT转换



我的输入被定义为

{
"lineId": "1",
"Collection": {
"services": [
{
"Code": "TB",
"Type": [
"Data"
]
},
{
"Code": "MAGTB",
"Type": [
"Data"
]
}
]
},
"promotions": [
{
"Id": "1"
},
{
"Id": "2"
}
]
}

我想把我的输出作为

{
"lineId": "1",
"Collection": {
"services": [
{
"Code": "TB",
"Type": [
"Data"
],
"promotions": [
{
"Id": "1"
},
{
"Id": "2"
}
]
},
{
"Code": "TB2",
"Type": [
"Data"
],
"promotions": [
{
"Id": "1"
},
{
"Id": "2"
}
]
}
]
}
}

如有任何帮助,我们将不胜感激。

我是JOLT的新手。我在从第一个数组内部导航到第二个数组时遇到了问题。

我尝试过的不完整的转换:

[
{
"operation": "shift",
"spec": {
"Collection": {
"services": {

"*": "Collection.services[].&",
"@(3,lineId)": "lineId",
"@(3,promotions)":{
"*":
}
}
}
}
}
]

编辑:现在尝试这个

[
{
"operation": "shift",
"spec": {
"Collection": {
"services": {
"*": "Collection.services[]",
//  "*": "&",
"@(3,lineId)": "lineId",
"@(3,promotions)": {
"*": {
"Id": "Id"
}
}
}
}
}
}
]

我只需要想办法将Id列表移动到服务数组中的对象中。

第2版:

[
{
"operation": "shift",
"spec": {
"Collection": {
"services": {
"*": {
"*": "Collection.services[&1].&",
"@(3,lineId)": "Collection.services[&1].lineId",
"@(3,promotions)": "Collection.services[&1].promotions"
}
}
}
}
}
]

我想这就是您想要的规格?

[
{
"operation": "shift",
"spec": {
"lineId": "lineId",
"Collection": {
"services": {
"*": {
"@(3,promotions)": "Collection.services[&1].promotions",
"*": "Collection.services[&1].&"
}
}
}
}
}
]

最新更新