jsonazurecsvazure-logic-apps

How to dynamically create a CSV out of parsed JSON in a Logic App


Overall, I have a logic app that looks like this:

enter image description here

The uploaded blob CSVs will have different structures, but will always contain a column that I do not want to send out to the recipients. It's a distribution list that I will use to compose the email (already achieved this part), but I'm having trouble handling this for all cases. My "Select" and "Create CSV" activities (to ultimately exclude the distribution list) are hardcoded in for a specific structure. Like so:

enter image description here

How can I handle this for all cases where something like a "DistributionList" column always exists but others are unknown. (I'm already handling the parsing of the JSON dynamically by just inserting "{}" for the schema)


Solution

  • You can use Execute JavaScript Code to remove the Distribution List using below design:

    enter image description here

    var ri_tst_ar = workflowContext.actions.Parse_JSON.outputs.body;
    var ri_out = ri_tst_ar.map(function(rith) {
        var tst = {};
        for (var ri in rith) {
            if (ri !== "DistributionList") {
                tst[ri] = rith[ri];
            }
        }
        return tst;
    });
    return ri_out;
    

    Then:

    enter image description here

    Output:

    Distribution List is removed using the code.

    enter image description here

    enter image description here