1👍
Perhaps not an answer (assuming usage of NewtonsoftJSON).
Implementing a custom ContractResolver
will sort this out for you. You can traverse through the property and build JSON as you may wish for. There is a SO question already showing how to implement custom resolver. You can find it here.
The class may look something of this sort then:
class Sample
{
public string Name { get; set; }
public Collection<DataClass> Data { get; set; }
}
public class DataClass
{
public string AttributeName { get; set; }
public int Value { get; set; }
}
The justification for this as far as I am concerned is separation of concern. The server side code should not really be worried as to how the client side control needs the data as. Specially if you are writing APIs which may or may not be consumed by multiple client types. Server would serve the data in a specific format and it’s manipulations to provide a user friendly display must be handled separately. This manipulation can either be done on the server (easily removable if needed for another client) or at the client side itself thus retaining client specific code at one place.
I hope that makes sense.