title: Renaming a JSON key in Python
body: <p>I am trying to process some logs and post the log contents to an API for further processing. Before I post the data to the API I need to rename the keys but it doesn't seem to work. </p>
  
  <p>This is what I have so far.</p>
  
  <pre><code>import re
  import json
  
  logs = ['2016-10-13 17:04:50 - info - uri:"GET x/y/z" ip:1.1.1.1 Rs:{"key1": "data", "key2":"data"}',
          '2016-10-13 17:05:10 - info - uri:"GET x/y/z" ip:1.1.1.1 Rs:{"key1": "data", "key2":"data"}']
  
  newLogs = []
  for log in logs:
      data = (re.compile(r"Rs:({[^}]*})").search(log)).group(1))
      data.replace('key1','keyA').replace('key2','keyB')
      newLogs.append(data)
  
  
  # Current output - the keys are not changed
  print (newLogs)
  &gt;&gt;&gt;&gt; ['2016-10-13 17:04:50 - info - uri:"GET x/y/z" ip:1.1.1.1 Rs:{"key1": "data", "key2":"data"}',
        '2016-10-13 17:05:10 - info - uri:"GET x/y/z" ip:1.1.1.1 Rs:{"key1": "data", "key2":"data"}']
  
  #Desired output
  print (newLogs)
  &gt;&gt;&gt;&gt; ['2016-10-13 17:04:50 - info - uri:"GET x/y/z" ip:1.1.1.1 Rs:{"keyA": "data", "keyB":"data"}',
        '2016-10-13 17:05:10 - info - uri:"GET x/y/z" ip:1.1.1.1 Rs:{"keyA": "data", "keyB":"data"}']
  </code></pre>