我正试图为下面的数据应用颠簸。
输入
[
{
"id": "500",
"code": "abc",
"date": "2020-10-10",
"category": 1,
"amount": 100,
"result": 0
},
{
"id": "500",
"code": "abc",
"date": "2020-10-10",
"category": 2,
"amount": 200,
"result": 1
}
]使用
[
{
"operation": "shift",
"spec": {
"*": {
"id": "@(1,id).id",
"code": "@(1,id).code",
"date": "@(1,id).group1.date",
"category": "@(1,id).group1.group2[&1].category"
}
}
},
{
"operation": "cardinality",
"spec": {
"*": {
"id": "ONE"
}
}
},
{
"operation": "shift",
"spec": {
"*": ""
}
}
]电流输出
{
"id": "500",
"code": [
"abc",
"abc"
],
"group1": {
"date": [
"2020-10-10",
"2020-10-10"
],
"group2": [
{
"category": 1
},
{
"category": 2
}
]
}
}期望
{
"id": "500",
"code": "abc",
"group1": {
"date": "2020-10-10",
"group2": [
{
"category": 1
},
{
"category": 2
}
]
}
}如果我在基数中保留了代码和日期列,就可以了。但是在我的用例中,需要添加多个这样的列。有什么更好的方法来处理这种情况吗?
发布于 2022-03-10 08:32:53
您应该添加每个添加的节点,并使用"*"通配符来表示基数转换中属性的rest,如
{
"operation": "cardinality",
"spec": {
"*": {
"*": "ONE",
"group1": {
"*": "ONE",
"group2": "MANY"
}
}
}
}其中,"group2": "MANY"只提取各自列表的第一个元素,就会使group2被排除在外。
站点上的演示 http://jolt-demo.appspot.com/:

https://stackoverflow.com/questions/71419944
复制相似问题