check if input is an empty array or empty array of arrays and save as just empty array otherwise copy the array of objects. Any help is appreciated
{
"response": {
"body": {
"variables": {
"sample": {
"type": "Json",
"value": [
[
[]
]
],
"valueInfo": {}
}
}
}
}
}
My Spec:
[
{
"operation": "shift",
"spec": {
"response": {
"body": {
"variables": {
"sample": {
"value": "."
}
}
}
}
}
}
]
Expected output:
[]
CodePudding user response:
You can get rid of wrappers(square brackets) of the array by successively using split and join functions within the modify transformation in order to measure whether the size of the remaining array is zero or not, and then determine the results depending on this result such as
[
{
"operation": "modify-overwrite-beta",
"spec": {
"response": {
"body": {
"variables": {
"sample": {
"str0": "=toString(@(1,value))",
"str1": "@(1,str0[0])",
"str2": "=split('\\[', @(1,str1))",
"str3": "=join('',@(1,str2))",
"str4": "=split('\\]', @(1,str3))",
"sz": "=size(@(1,str4))"
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"response": {
"body": {
"variables": {
"sample": {
"sz": {
"0": { "@(2,str4)": "" },
"*": { "@(2,value)": "" }
}
}
}
}
}
}
}
]

