title: How to make json.dumps in Python ignore a non-serializable field
body: <p>I am trying to serialize the output of parsing some binary data with the Construct2.9 library. I want to serialize the result to JSON.</p>
  
  <p><code>packet</code> is an instance of a Construct class <code>Container</code>.</p>
  
  <p>Apparently it contains a hidden <code>_io</code> of type <code>BytesIO</code> - see output of <code>dict(packet)</code> below:</p>
  
  <pre><code>{
  'packet_length': 76, 'uart_sent_time': 1, 'frame_number': 42958, 
  'subframe_number': 0, 'checksum': 33157, '_io': &lt;_io.BytesIO object at 0x7f81c3153728&gt;, 
  'platform':661058, 'sync': 506660481457717506, 'frame_margin': 20642,
  'num_tlvs': 1, 'track_process_time': 593, 'chirp_margin': 78,
  'timestamp': 2586231182, 'version': 16908293
  }
  </code></pre>
  
  <p>Now, calling <code>json.dumps(packet)</code> obviously leads to a TypeError:</p>
  
  <pre><code>...
  
  File "/usr/lib/python3.5/json/__init__.py", line 237, in dumps
      **kw).encode(obj)
  File "/usr/lib/python3.5/json/encoder.py", line 198, in encode
      chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.5/json/encoder.py", line 256, in iterencode
      return _iterencode(o, 0)
  File "/usr/lib/python3.5/json/encoder.py", line 179, in default
      raise TypeError(repr(o) + " is not JSON serializable")
  TypeError: &lt;_io.BytesIO object at 0x7f81c3153728&gt; is not JSON serializable
  </code></pre>
  
  <p>However what I am confused about, is that running <code>json.dumps(packet, skipkeys=True)</code> results in the exact same error, while I would expect it to skip the <code>_io</code> field. What is the problem here? Why is <code>skipkeys</code> not allowing me to skip the <code>_io</code> field?</p>
  
  <p>I got the code to work by overriding <code>JSONEncoder</code> and returning <code>None</code> for fields of <code>BytesIO</code> type, but that means my serialized string contains loads of <code>"_io": null</code> elements, which I would prefer not to have at all...</p>