title: Python3 Convert 'CaseInsensitiveDict' to JSON
body: <p>I am working on what I assumed would be a simple problem but it has really confused. I am making an AD query in Python using the <a href="https://ldap3.readthedocs.io/en/latest/tutorial.html" rel="noreferrer">ldap3</a> module. This query is returning the data as generator of python dictionaries. When I run the <code>type()</code> command against the data it confirms that it is a dictionary. </p>
  
  <p>I need to convert this into JSON so that I can write it to a log file. First, I tried <code>json.dump(data, file)</code> but when I do that I receive this error:  <code>TypeError: Object of type 'CaseInsensitiveDict' is not JSON serializable</code></p>
  
  <p>If I try and convert the dictionary to a string first the data is written with quotes and inner fields are left with single quotes so it isn't true JSON - it comes out looking like this: <code>"{'key': 'value'}"</code></p>
  
  <p>Here is what I have: </p>
  
  <pre><code>with open(outfile, 'w') as outfile:
      for entry in entry_generator: # Entry is equal to a dictionary of AD attributes
          json.dump(entry, outfile) # I have also tried json.dump(str(entry), outfile) etc
  </code></pre>
  
  <p>I have been searching the interwebs and I see a lot about this issue with the <code>requests</code> module but nothing that seems to fix my situation. </p>
  
  <p>With the ldap3 module there is a method <code>entry_to_json()</code> which I used in other scripts. It doesn't seem to work here because of the generator, if anyone knows how to make that work again it could solve my problem. Thoughts? </p>