title: Django filter if an optional key in json exists
body: <p>I have a model <code>X</code> with a custom json fied <code>data</code> which may or may not have these keys: <code>key1</code>, <code>key2</code>, <code>key3</code>.
  I need a way to filter all instances with <code>key1</code>.</p>
  
  <p>I have tried doing this:</p>
  
  <pre><code>queryset = X.objects.all()
  queryset = queryset.annotate(
  has_key1=(
      Case(
          When(~Q(data__key1__in=[None, '']), then=True),
          default=False,
          output_field=models.BooleanField())
      )
  )
  </code></pre>
  
  <p>But <code>queryset.filter(has_key1=True)</code> returns nothing yet there are some records with key1.</p>
  
  <p>A direct filter: <code>queryset.filter(data__key1__in=[1])</code> works okay.
  Anyone with a solution to this? Thank you.</p>