Good morning,
I have a folder full of json format files which need to be sent via C# inside a script task inside SSIS to an API. The SSIS will loop through (foreach is setup) and send each file.
Below is the format of all the files(all same format but different values etc):
JavaScript
"Time":"2018-10-21T00:08:03",
"Control_Code": "JKX",
"metrics": [
{
"Metric": 3721,
"Organisation":"AD450",
"Value": 20,
"Datetime":"2018-10-21T00:08:00"
},
{
"Metric": 1234,
"Organisation":"HG650",
"value": 88,
"datetime":"2018-10-21T00:08:00"
}
]
}Can anybody assist or point me in the right direction on how to do this please?
I've been digging around online and found the following example starting point. Not sure if this can be adapted accordingly? Any help is appreciated.


Amit MohantyRank #112 · 20K reputationPosted Oct 18, 2023, 7:35 AM EDT
Try this:
string filePath = @"your-path\test.json"; if (File.Exists(filePath)) { try { // Read the JSON file string jsonData = File.ReadAllText(filePath); using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://your-url.com"); var responce = client.PostAsync("/url-path", new StringContent(jsonData, Encoding.UTF8, "application/json")).Result; var responceContent = responce.Content.ReadAsStringAsync(); } } catch (Exception ex) { Console.WriteLine($"Error reading or parsing the JSON file: {ex.Message}"); } } else { Console.WriteLine("The JSON file does not exist in the specified folder."); }