I want to deserialize a json object in c# using JsonSerializer.Deserialize
of System.Text.Json.
The json looks like this:
{
"id":10,
"authorization_ids":[
],
"karma_user_ids":[
2
],
"group_ids":{
"2":[
"full"
],
"4":[
"read"
],
"5":[
"overview"
],
"7":[
"change",
"overview"
],
"10":[
"create"
]
}
}
But the property group_ids
contains objects with dynamic property names that actually correspond to the ID of a group.
{
2 : {full}
4 : {read}
5 : {overview}
7 : {change, overview}
10 : {create}
}
Now I want to deserialize group_ids to an object like this:
public class GroupPermission
{
public int GroupID { get; set; }
public Permission Permission { get; set; }
public GroupPermission() { }
}
[Flags]
public enum Permission
{
full = 1,
read = 2,
overview = 4,
change = 8,
create = 16
}
Is this possible? Can someone point me the right direction?