title: Filterting a json file by removing objects that contain certain keys
body: <p>I'm having a bit of trouble filtering my json file. Basically I have a json file where each line is a different json object (I know this is not the normal valid format but it's what I have to work with), and I want to go through each line and check if it contains either 1 of 2 keys (e.g. &quot;name&quot; or &quot;firstname&quot;). If either of the 2 keys exist in the json object, I want to keep it. And if not, I want to remove it. So at the end, I will have an output json file that doesn't include the objects missing those keys.</p>
  <p>I've tried out a bunch of different things but I can't seem to get it to work, this is what I have so far:</p>
  <pre><code>jsonList = []
  
  with open(filename) as f:
          for json_line in f:
              obj = json.loads(json_line)
              checker(obj)
  
  def checker(obj):
      check = 0
      if (&quot;name&quot; in obj):
          check = 1
      if (&quot;firstname&quot; in obj):
          check = 1
      if (check == 1):
          jsonList.append(obj)
  </code></pre>
  <p>When I try printing jsonList after it just gives me an empty list <code>[]</code>, so my <code>check</code> variable never changed to 1 even though there are json objects in my file that have those keys.</p>
  <p>My json file looks something like this: <em>(note: number of things inside each object isn't guaranteed so I can't just check for that)</em></p>
  <pre><code>{&quot;name&quot;: &quot;name1&quot;, &quot;date&quot;: &quot;2018-11-13&quot;, &quot;age&quot;: 32}
  {&quot;firstname&quot;: &quot;name2&quot;, &quot;date&quot;: &quot;2019-05-09&quot;, &quot;age&quot;: 40}
  {&quot;date&quot;: &quot;2019-11-04&quot;, &quot;age&quot;: 35}
  </code></pre>
  <p>Does anyone have any ideas on what I could do? Or if you know why what I tried here didn't work?</p>