Jolt 小组赛成绩
Group results in Jolt
我正在尝试根据 json 字段将一些数据分组到数组中。
[
{
"Type": "Cash",
"Value1": "668131AA3",
"ParentId": "87984E01",
"CashId": "6688E582",
"StockId": null
},
{
"Type": "Stock",
"Value1": "668131AA3",
"ParentId": "87984E01",
"CashId": "1FD714A9",
"StockId": "1FD714A9"
},
{
"Type": "Stock",
"Value1": "668131AA3",
"ParentId": "87984E01",
"CashId": "0635B045",
"StockId": "0635B045"
},
{
"Type": "Cash",
"Value1": "668131AA3",
"ParentId": "87984E01",
"CashId": "47E65472",
"StockId": null
}
]
所需的输出是:
"Value1": "668131AA3",
"ParentId": "87984E01",
"CashPayouts" : [
{"CashId": "6688E582"},
{"CashId": "87984E01"}
],
"StockPayouts" : [
{"StockId": "1FD714A9","CashId": "1FD714A9"},
{"StockId": "0635B045","CashId": "0635B045"}
]
}
基本上,如果 Type=Cash
,CashId
字段应该分组在 CashPayouts
数组中。对于 Type=Stock
,将两个字段分组到 StockPayouts
数组中。
是否可以在 Jolt 中进行此转换?如果是真的,那又如何?
谢谢,
胡安
这应该完成示例:
[
{
"operation": "shift",
"spec": {
"*": {
"Value1": "Value1",
"ParentId": "ParentId",
"Type": {
"Stock": {
"@(2)": {
"CashId": "t.StockPayouts[&4].CashId",
"StockId": "t.StockPayouts[&4].StockId"
}
},
"Cash": {
"@(2)": {
"CashId": "t.CashPayouts[&4].CashId"
}
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": "=recursivelySquashNulls",
"Value1": "=firstElement(@(1,Value1))",
"ParentId": "=firstElement(@(1,ParentId))"
}
},
{
"operation": "shift",
"spec": {
"Value1": "Value1",
"ParentId": "ParentId",
"t": ""
}
}
]
我正在尝试根据 json 字段将一些数据分组到数组中。
[
{
"Type": "Cash",
"Value1": "668131AA3",
"ParentId": "87984E01",
"CashId": "6688E582",
"StockId": null
},
{
"Type": "Stock",
"Value1": "668131AA3",
"ParentId": "87984E01",
"CashId": "1FD714A9",
"StockId": "1FD714A9"
},
{
"Type": "Stock",
"Value1": "668131AA3",
"ParentId": "87984E01",
"CashId": "0635B045",
"StockId": "0635B045"
},
{
"Type": "Cash",
"Value1": "668131AA3",
"ParentId": "87984E01",
"CashId": "47E65472",
"StockId": null
}
]
所需的输出是:
"Value1": "668131AA3",
"ParentId": "87984E01",
"CashPayouts" : [
{"CashId": "6688E582"},
{"CashId": "87984E01"}
],
"StockPayouts" : [
{"StockId": "1FD714A9","CashId": "1FD714A9"},
{"StockId": "0635B045","CashId": "0635B045"}
]
}
基本上,如果 Type=Cash
,CashId
字段应该分组在 CashPayouts
数组中。对于 Type=Stock
,将两个字段分组到 StockPayouts
数组中。
是否可以在 Jolt 中进行此转换?如果是真的,那又如何?
谢谢, 胡安
这应该完成示例:
[
{
"operation": "shift",
"spec": {
"*": {
"Value1": "Value1",
"ParentId": "ParentId",
"Type": {
"Stock": {
"@(2)": {
"CashId": "t.StockPayouts[&4].CashId",
"StockId": "t.StockPayouts[&4].StockId"
}
},
"Cash": {
"@(2)": {
"CashId": "t.CashPayouts[&4].CashId"
}
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": "=recursivelySquashNulls",
"Value1": "=firstElement(@(1,Value1))",
"ParentId": "=firstElement(@(1,ParentId))"
}
},
{
"operation": "shift",
"spec": {
"Value1": "Value1",
"ParentId": "ParentId",
"t": ""
}
}
]