json - check if input is an empty array or empty array of arrays and save as just empty array otherwise copy the array of objects - TagMerge
3check if input is an empty array or empty array of arrays and save as just empty array otherwise copy the array of objectscheck if input is an empty array or empty array of arrays and save as just empty array otherwise copy the array of objects

check if input is an empty array or empty array of arrays and save as just empty array otherwise copy the array of objects

Asked 1 years ago
1
3 answers

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)": "" }
              }
            }
          }
        }
      }
    }
  }
]

enter image description here

Source: link

0

.length Example Syntax
Const myArray = [‘Horses’, ‘Dogs’, ‘Cats’];
Using the length property, we can check the length of the array:
myArray.length
First, let's create a new array with no elements.
const arr = []
Now we can check if the array is empty by using .length.
arr.length

Source: link

0

//To check if an array is empty using javascript
function arrayIsEmpty(array) {
    //If it's not an array, return FALSE.
    if (!Array.isArray(array)) {
        return FALSE;
    }
    //If it is an array, check its length property
    if (array.length == 0) {
        //Return TRUE if the array is empty
        return true;
    }
    //Otherwise, return FALSE.
    return false;
}
Demonstration of checking if the array is empty using Javascript
var fruitArr = new Array('Apple', 'Mango', 'Grapes');

//An example of a JavaScript array that is empty.
var arrTwo = new Array();

console.log(arrayIsEmpty(fruitArr)); //returns FALSE
console.log(arrayIsEmpty(arrTwo)); //returns TRUE
Output
FALSE
TRUE
Array.isArray([]);
Array.isArray([3]);
Array.isArray(new Array());
Array.isArray(new Array('apple', 'mango', 'grapes'));
Array.isArray(new Array(5));
Array.isArray(Array.prototype);
Array.isArray();
Array.isArray({});
Array.isArray(null);
Array.isArray(undefined);
Array.isArray(21);
Array.isArray('Random String');
Array.isArray(true);
Array.isArray(false);
Array.isArray(new Uint8Array(32));
Array.isArray({
    __proto__: Array.prototype
});

Source: link

Recent Questions on json

    Programming Languages