我想向数组中的所有字段添加一个常量前缀,例如“0”。
这是输入:
{
"input": [
"1_ANY",
"2_ANY",
"3_ANY"
]
}
Output:
{
"output" : [ "1", "2", "3" ]
}
预期输出:
{
"output" : [ "01", "02", "03" ]
}
规格:
[
{
"operation": "shift",
"spec": {
"input": {
"*": {
"*_*": {
"$(0,1)": "output"
}
}
}
}
}
]
有没有办法为字符串数组中的所有元素添加常量前缀?
您可以将修改覆盖测试版规范添加到您创建的规范中以进行串联,如下所示:
[
{
"operation": "shift",
"spec": {
"input": {
"*": {
"*_*": {
"$(0,1)": "output"
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"output": {
"*": "=concat('0',@0)"
}
}
}
]
或者您可以使用两个移位操作来完成,如下所示:
[
{
"operation": "shift",
"spec": {
"input": {
"*": {
"*_*": {
"$": "0&(1,1)"
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"$": "output"
}
}
}
]