I have an exported flows.json file of a NodeRed flow, and from that I want to parse the property "connection" of nodes with type "MSSQL". But I get always empty result. I have noticed when debugging the code that a property like "connection" is not existing programatically, although I can see it in the Nodered UI. Instead I can just parse the property "MSSQLCN" which is something like an ident number. How can I parse the node property "connection" via code using this "MSSQLCN" ident number? After that I would search for the global configuration node with that name and parse the properites "Server" and "Database"
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json.Linq;
class Program
{
static void Main(string[] args)
{
try
{
// Specify the path to the Node-RED flow.json file
string inputFilePath = @"C:\flow.json";
string outputFilePath = @"C:\result.txt";
// Read the JSON file
string jsonContent = File.ReadAllText(inputFilePath);
// Parse the JSON content
JArray flowArray = JArray.Parse(jsonContent);
// List to store connection properties of MSSQL nodes
List<string> mssqlConnections = new List<string>();
// Iterate through each node in the flow
foreach (JObject node in flowArray)
{
// Check if the node type is MSSQL
if (node["type"]?.ToString() == "MSSQL")
{
// Get the connection property
string connection = node["connection"]?.ToString();
if (!string.IsNullOrEmpty(connection))
{
mssqlConnections.Add(connection);
}
}
}
// Write the connection properties to the output file
File.WriteAllLines(outputFilePath, mssqlConnections);
Console.WriteLine($"Extraction completed. Results saved to {outputFilePath}");
}
catch (Exception ex)
{
Console.WriteLine("An error occurred: " + ex.Message);
}
}
}