Reputation: 446
After some jolt shift and default operations I'm left with
"items" : [ null, "-70.7", "-70.4", "-68.5", null, "tmp" ]
The last thing I want to achieve is remove this "tmp" string from the array.
Any ideas how to achieve that? I've already tried different things but no results :/
Upvotes: 0
Views: 496
Reputation: 65323
You can use a shift transformation through combining indexes of the array except for the last element by pipe(|) operators such as
[
{
"operation": "shift",
"spec": {
"items": {
"0|1|2|3|4": {
"@": "&2.[&1]"
}
}
}
}
]
The demo on http://jolt-demo.appspot.com/ :
A dynamical solution might be successive transformations, also through adding modify transformation.
An extra conversion from null
to "null"
is performed in the below specification to apply the technique of exchanging the key and value pairs in order to prevent the extinction issue of null
values such as
[
{
"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)]"
}
}
}
}
]
The demo :
or the more dynamical solution, even keeping null values might be
[
//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]" }
}
}
}
}
}
}
]
Upvotes: 1