Jolt - 从数组中删除最后一个元素
Jolt - Remove last element from array
经过一些颠簸的转变和默认操作后,我剩下
"items" : [ null, "-70.7", "-70.4", "-68.5", null, "tmp" ]
我想要实现的最后一件事是从数组中删除这个“tmp”字符串。
有什么实现方法吗?我已经尝试过不同的方法但没有结果:/
您可以使用 shift 转换,通过 pipe[=最后一个元素 以外的数组索引组合pipe(|) 运算符如
[
{
"operation": "shift",
"spec": {
"items": {
"0|1|2|3|4": {
"@": "&2.[&1]"
}
}
}
}
]
http://jolt-demo.appspot.com/ 上的演示:
动态解决方案可能是连续变换,也可以通过添加 修改 变换。
在下面的规范中执行从 null
到 "null"
的额外转换以应用该技术交换键和值对以防止 null
值的灭绝问题,例如
[
{
"operation": "modify-overwrite-beta",
"spec": {
"items": ["=toString", "null"],
"sz_items": "=size(@(1,items))",
"sz_items_minus_1": "=intSum(-1,@(1,sz_items))"
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": "&"
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"$": "[&].@(0)"
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": {
"$": "items[@(0)]"
}
}
}
}
]
演示:
或更动态的解决方案,甚至 keeping null 值也可能是
[
//determine the length of the lists(arrays) except for the rightmost element
{
"operation": "modify-overwrite-beta",
"spec": {
"sz_items": "=size(@(1,items))",
"sz_items_minus_1": "=intSum(-1,@(1,sz_items))"
}
},
//get rid of unnecessary attribute
{
"operation": "remove",
"spec": {
"sz_items": ""
}
},
//determine the rightmost element as a list
{
"operation": "shift",
"spec": {
"*": {
"*": "items.&"
},
"@": "xxx"
}
},
//convert the values of the elements of the "items" to lists
{
"operation": "modify-overwrite-beta",
"spec": {
"items": {
"*": "=toList(@(1,&))"
}
}
},
//determine the length of the elements of the "items" to lists
{
"operation": "modify-overwrite-beta",
"spec": {
"items": {
"*": ["=size(@(1,&))", 0]
}
}
},
//filter out generated elements with multiple component(eg. keep 0 or 1)
//in order to reform the list
{
"operation": "shift",
"spec": {
"xxx": {
"items": {
"*": {
"@(3,&1.&)": {
"0|1": { "@2": "&4[&3]" }
}
}
}
}
}
}
]
经过一些颠簸的转变和默认操作后,我剩下
"items" : [ null, "-70.7", "-70.4", "-68.5", null, "tmp" ]
我想要实现的最后一件事是从数组中删除这个“tmp”字符串。
有什么实现方法吗?我已经尝试过不同的方法但没有结果:/
您可以使用 shift 转换,通过 pipe[=最后一个元素 以外的数组索引组合pipe(|) 运算符如
[
{
"operation": "shift",
"spec": {
"items": {
"0|1|2|3|4": {
"@": "&2.[&1]"
}
}
}
}
]
http://jolt-demo.appspot.com/ 上的演示:
动态解决方案可能是连续变换,也可以通过添加 修改 变换。
在下面的规范中执行从 null
到 "null"
的额外转换以应用该技术交换键和值对以防止 null
值的灭绝问题,例如
[
{
"operation": "modify-overwrite-beta",
"spec": {
"items": ["=toString", "null"],
"sz_items": "=size(@(1,items))",
"sz_items_minus_1": "=intSum(-1,@(1,sz_items))"
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": "&"
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"$": "[&].@(0)"
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": {
"$": "items[@(0)]"
}
}
}
}
]
演示:
或更动态的解决方案,甚至 keeping null 值也可能是
[
//determine the length of the lists(arrays) except for the rightmost element
{
"operation": "modify-overwrite-beta",
"spec": {
"sz_items": "=size(@(1,items))",
"sz_items_minus_1": "=intSum(-1,@(1,sz_items))"
}
},
//get rid of unnecessary attribute
{
"operation": "remove",
"spec": {
"sz_items": ""
}
},
//determine the rightmost element as a list
{
"operation": "shift",
"spec": {
"*": {
"*": "items.&"
},
"@": "xxx"
}
},
//convert the values of the elements of the "items" to lists
{
"operation": "modify-overwrite-beta",
"spec": {
"items": {
"*": "=toList(@(1,&))"
}
}
},
//determine the length of the elements of the "items" to lists
{
"operation": "modify-overwrite-beta",
"spec": {
"items": {
"*": ["=size(@(1,&))", 0]
}
}
},
//filter out generated elements with multiple component(eg. keep 0 or 1)
//in order to reform the list
{
"operation": "shift",
"spec": {
"xxx": {
"items": {
"*": {
"@(3,&1.&)": {
"0|1": { "@2": "&4[&3]" }
}
}
}
}
}
}
]