title: How can I edit/rename keys during json.load in python?
body: <p>I have a json file ( ~3Gb ) that I need to load into mongodb. Quite a few of the json keys contain a . (dot), which causes the load into mongodb to fail. I want to the load the json file, and edit the key names in the process, say replace the dot with an empty space. Using the following python code</p>
  
  <pre><code>import json
  
  def RemoveDotKey(dataPart):
      for key in dataPart.iterkeys():
          new_key = key.replace(".","")
          if new_key != key:
              newDataPart = deepcopy(dataPart)
              newDataPart[new_key] = newDataPart[key]
              del newDataPart[key]
              return newDataPart
      return dataPart
  
  new_json = json.loads(data, object_hook=RemoveDotKey) 
  </code></pre>
  
  <p>The object_hook called RemoveDotKey should iterate over all the keys, it a key contains a dot, create a copy, replace the dot with a space, and return the copy. Created a copy of dataPart, since not sure if I can iterate over dataPart's keys and insert/delete key value pairs at the same time.</p>
  
  <p>There seems to be an error here, all the json keys with a dot in them are not getting edited. I am not very sure how json.load works. Also am new to python ( been using it for less than a week )</p>