'How to filter queryset using item inside a list in a JSON file in Django?

I have JSON files that are structured like this in my database:

}
    "user" : {
        "contacts" : [
            {
                "type" : "email",
                "data" : "[email protected]"
            },
            {
                "type" : "phone_number",
                "data" : "4444-4444"
            },
            {
                "type" : "email",
                "data" : "[email protected]"
            },
            
            ...
            
        ],
        "name" : "Bob"
    }
}

What I want is to filter the queryset so I end up only having users that have an account with an email registered.

Anyone knows how to make this work?

I am aware of user__contacts__0__type=email but the list doesn't have a fixed size.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source