I have a question related to Json. Let me start by giving you my Json sample:
{
"watch": [
{
"path": "C:/Temp",
"conditions": "*.log",
"actions": ""
},
{
"path": "C:/Temps",
"conditions": ".log",
"actions": ""
}
]
}
I want to watch directories. So I my Json will have an array of data.
I would like to cross check if I'm doing some stuff properly. I'm a C# developer but I'm quite new to .NET Core. Usually I load my Json file by using serialization from Newtonsoft package. With .NET Code I have the feeling we do this a little bit differently. I'm doing this:
static void Main(string[] args)
{
var configurationBuilder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("config.json", optional: true, reloadOnChange: true)
.Build();
}
Then I can access my data by using this
configurationBuilder["watch:0:path"]
"C:/Temp"
Great but this is not what I want. I want to loop on my array. With the ConfigurationBuilder I have the feeling I cannot use the data as a loop. It seem all data from the config file is a key
This is logic because my config file can be anything. The builder has no guarantee my array will always have the same objects. So the builder consider each element in my arrays as a unique token. I can understand this.
So, how can I load my config or this Json file in a structured object? Is there a way to load this as a config file in a better way? Because for real I have 2 object in my array and I would like to loop on them. For each object I do something.