Skip array element if variable blank\null in CSV

@nmasson-pbc

I haven’t actually tried this but in theory it should work …

For the POST body …

"Array1": [ {{postVars}} ]

I don’t know what your actual CSV vars are but this is what would go into “Pre-req” …

var var_1 = pm.iterationData.get("var1");
var var_2 = pm.iterationData.get("var2");
var var_3 = pm.iterationData.get("var3");

var postVars = '{ "Id": "' + var1 + '" }';

if ( var_2 !== '' ) {
    postVars = postVars + ',{ "Id": "' + var_2 + '" }';
}
if ( var_3 !== '' ) {
    postVars = postVars + ',{ "Id": "' + var_3 + '" }';
}

Like I said above, I haven’t actually run this but you could try it and tweak it if needed.

2 Likes