Django queryset filter empty JSONField

Viewed 992

I would like to filter a JSONField my_fieldwhere the JSon is not empty. In the documentation there are has_keyand has_any_key methods but I don't know the possible keys in advance. In SQL it should be something like:

select * from my_model where cardinality(my_field)>0;
1 Answers

Found a way to achieve using iexact:

MyObject.objects.filter(my_field__iexact="{}")
Related