C#C
C#4y ago
Davaaron

Map complex object (dictionary) from appsettings.json to model

Hi,
i have a complex appsettings.json like this
"interceptor": {
    "interactionType": "redirect",
    "protectedResourceMap": [
      ["https://graph.microsoft.com/v1.0/me", ["user.read"]]
    ]
}


How can I map this?
I have a class definition
public class MSAL 
{
  public MSALInterceptorConfig Interceptor { get; set; }
}

public class MSALInterceptorConfig
{
  public string? InteractionType { get; set; }
  public List<Dictionary<string, List<string>>>? ProtectedResourceMap { get; set; }
}


and read the config like
var builder = WebApplication.CreateBuilder(args);
var config = builder.Configuration;
var clientConfig = config.Get<MSAL>();


When I check the clientConfig object, I see that the ProtectedResourceMap has one entry: key="1" and value="user.read". How can I fix it so I have a list of dictionary entries?
Was this page helpful?