I'm working in UIPath and trying to put together a single JSON configuration file for a library. My hands are sort of tied as far what functionality in VB.Net I can use but I'd like to filter my properties by environment. I'm able to successfully filter out the environment I'm not concerned with but I'm stuck with the existing environment property at the highest level of the JSON structure. I want to get rid of that one too after I know which one I want to keep.
Starting Point
{
"Development": {
"Database": {
"DB 1": {
"Server": "Foo",
"Application Name": "App1"
},
"DB 2": {
"Server": "Boo",
"Application Name": "App2"
}
}
},
"Production": {
"Database": {
"DB 1": {
"Server": "FooFoo",
"Application Name": "App1"
},
"DB 2": {
"Server": "BarBar",
"Application Name": "App2"
}
}
}
What I want to get to based on Environment (Development or Production)
{
"Database": {
"DB 1": {
"Server": "Foo",
"Application Name": "App1"
},
"DB 2": {
"Server": "Boo",
"Application Name": "App2"
}
}
Here is what I've tried so far:
Read JSON File to String
Deserialize to Newtonsoft JObject
Filter by environment
configData.Descendants .OfType(Of JProperty) .Where(Function(attr) attr.Name.ToUpper = "PRODUCTION" Or attr.Name.ToUpper = "DEVELOPMENT" And attr.Name.ToUpper <> environment.ToUpper) .ToList() .ForEach(Sub(attr) attr.Remove())
Result
{
"Development": {
"Database": {
"DB 1": {
"Server": "Foo",
"Application Name": "App1"
},
"DB 2": {
"Server": "Boo",
"Application Name": "App2"
}
}
}
From here is where I'm stuck and can't seem to get anything to work. I want to be able to access my configuration properties without the caller knowing what environment its in.
Something like
configuration("Database")("DB 1")
Versus
configuration(environment)("Database")("DB 1")
If I'm taking a stupid approach to this altogether I'd also accept that as an answer as well. I've never really played with VB or .Net before so its all fairly new to me. I'm understanding some things but am far from really understanding anything powerful.