Export CSV to json with C# script component

I found this: SSIS: C# CODE TO CONVERT CSV FILE JSON FILE FORMAT

It shows how to convert a CSV file to JSON and is fairly simple. The Powershell code is also quite simple but I would call it differently. It is actually easier to call Powershell from a script component...you can do something like this:

using (PowerShell powerShell = PowerShell.Create())
{
    // Source functions.
    powerShell.AddScript(PsScript);
    powerShell.Invoke();

    // Call function contained in sourced script above.
    powerShell.AddCommand("My-Function");
    powerShell.AddParameter("ParamA", varA);
    powerShell.AddParameter("ParamB", varB);
    powerShell.AddParameter("ParamC", varC);
    powerShell.AddParameter("ParamD", varD);

    results = powerShell.Invoke();
}

When you add the script - it can be an actual file or the actual code with parameters defined...

1 Like