Overwriting to_representation method on a Serializer

I am overwriting to_representation method on a Serializer in order to be able to return key/val pair Object as a result instead of a default array. This is the method overwritten :

def to_representation(self, instance):
row = super(DataSerializer, self).to_representation(instance)
return {row[“d”]: row}

And although it works fiine and actually return a key/val pair Object, but the object it self comes in a array as it’s only element. How can I handle this issue ? I tried overwriting list method on the ViewSet like this :

def list(self, request, *args, **kwrags):
queryset= self.filter_queryset(self.get_queryset())
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)

but returned me only first element of my data.

I think we’re going to need some additional details, and/or some sample data that you’re working with here - along with an explanation / demonstration of what you’re getting compared to what you’re expecting to see.

(Also, when you’re posting code here, please enclose it between lines consisting only of three backtick - ` characters to retain the formatting of the code. This means you’ll have a line that is only `\`, followed by your lines of code, followed by another line of ```. You can also go back and edit your original post to apply that formatting. It makes everything a lot easier to read.)