将块平面阵列摇晃成两对
Jolt transformation chunk flat array into pairs of two
我正在尝试将两个成对分组到一个平面列表中,请注意成对的数量可以是可变的(例如 0、2、4、6 等等)。
见意input/output。
输入:
{
"coordinates": [
1.1,
5.1,
1.2,
5.3,
1.3,
5.5
]
}
输出:
{
"coordinates": [
[1.1, 5.1],
[1.2, 5.3],
[1.3, 5.5],
]
}
这是否可以使用 Jolt 转换轻松实现?
是的,你可以通过使用连续的转换来实现它,比如
[
//index each values seperately
{
"operation": "shift",
"spec": {
"*": {
"*": "&1.&"
}
}
},
// convert values to string type so as to prevent the issue of truncation of decimal parts of those values
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": "=toString(@(1,&))"
}
}
},
// exchange key-value pairs
{
"operation": "shift",
"spec": {
"*": {
"*": {
"$": "&2.@(0)"
}
}
}
},
{
// increment the values by 1 in order to prepare them for modular arithetic logic held in the following steps
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": "=intSum(@(1,&),1)"
}
}
},
{
// pairs means to have two components, then need to divide the values by 2 along with rounding to the nearest grater integer
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": "=divideAndRound(0,@(1,&),2)"
}
}
},
{
// exchange key-value pairs back while keeping the name of the object("coordinates")
"operation": "shift",
"spec": {
"*": {
"*": {
"$": "&2.@(0)"
}
}
}
},
{
// dissipate each component of the list to their proper place
"operation": "shift",
"spec": {
"*": {
"*": "&1[]"
}
}
}
]
我正在尝试将两个成对分组到一个平面列表中,请注意成对的数量可以是可变的(例如 0、2、4、6 等等)。
见意input/output。
输入:
{
"coordinates": [
1.1,
5.1,
1.2,
5.3,
1.3,
5.5
]
}
输出:
{
"coordinates": [
[1.1, 5.1],
[1.2, 5.3],
[1.3, 5.5],
]
}
这是否可以使用 Jolt 转换轻松实现?
是的,你可以通过使用连续的转换来实现它,比如
[
//index each values seperately
{
"operation": "shift",
"spec": {
"*": {
"*": "&1.&"
}
}
},
// convert values to string type so as to prevent the issue of truncation of decimal parts of those values
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": "=toString(@(1,&))"
}
}
},
// exchange key-value pairs
{
"operation": "shift",
"spec": {
"*": {
"*": {
"$": "&2.@(0)"
}
}
}
},
{
// increment the values by 1 in order to prepare them for modular arithetic logic held in the following steps
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": "=intSum(@(1,&),1)"
}
}
},
{
// pairs means to have two components, then need to divide the values by 2 along with rounding to the nearest grater integer
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": "=divideAndRound(0,@(1,&),2)"
}
}
},
{
// exchange key-value pairs back while keeping the name of the object("coordinates")
"operation": "shift",
"spec": {
"*": {
"*": {
"$": "&2.@(0)"
}
}
}
},
{
// dissipate each component of the list to their proper place
"operation": "shift",
"spec": {
"*": {
"*": "&1[]"
}
}
}
]