2

Below is an extract from a json response received from a service.

aggregations: {
    gender: {
           ...other data
    }
}

The service will return same structure every time but with different aggregation type based on some parameters. So the term "gender" can be "age" or "city" or anything else. I am looking for a way to create a .Net object, is possible, with a dynamic property name so that I don't need to have separate object for each aggregation. something like this:

public class Aggregation    {
    [JsonProperty(PropertyName = "<dynamic value based on json response>")]
    public List<string> AggregationValues { get; set; }
}

Is there any other way to achieve this? Thank you for your help.

user3731783
  • 718
  • 1
  • 7
  • 31
  • 1
    Take a look at this answer http://stackoverflow.com/questions/26882986/overwrite-json-property-name-in-c-sharp – smoksnes Jun 16 '16 at 05:07
  • I have done this with custom ContractResolver as @smoksnes suggests and it worked pretty well. At the same time, I would try to deserialize it as Dictionary because thats what it essentially is. – Kaspars Ozols Jun 16 '16 at 05:19

0 Answers0