I have a json object that is coming from an endpoint.
{
"user_info": {
"myapp1": {
"roles": [
"requestor"
]
},
"myapp2": {
"roles": [
"requests-edit",
"requests-view"
]
},
"account": {
"roles": [
"manage-account",
"manage-account-links",
"view-profile"
]
}
}
}
Based on this structure its pretty clear that there are two strongly typed objects. user_info
and roles
. However, the apps (myapp1, myapp2, account)
are not in an array, they are "dynamic" or "anonymous" objects.
What is the recommended way to get the roles with a known app name?
EG, some pseudo code.
// returns the sub objects as a dictionary of <string, Roles>;
var anonjson = JsonAnon.DeserializeOnProperty<string, Roles>("user_info");
var roles = anonjson.Where(x => x.Key.Value == "myapp2").FirstOrDefault();
// i forget what dictionaries use to get by key I put x.Key, this could be invalid.