title: Convert Nested Json to a single Key Value Pair
body: <p>I have a list of Keys  :</p>
  <ol>
  <li>Server</li>
  <li>Date</li>
  <li>Severity</li>
  <li>process</li>
  <li>message</li>
  </ol>
  <p>If there is a key &quot;events&quot; in my Dictionary, I need to replace the key with &quot;Message&quot; and the value of &quot;indicator-type&quot; will become the value of the message</p>
  <pre><code>List1=[
        {
          &quot;server&quot;: &quot;10.10.0.123&quot;,
          &quot;date&quot;: 1561994754,
          &quot;severity&quot;: &quot;INFO&quot;,
          &quot;process&quot;: &quot;webapp&quot;,
          &quot;message&quot;: &quot;server started.&quot;
        },
        {
          &quot;server&quot;: &quot;10.10.0.202&quot;,
          &quot;date&quot;: 1561994757000,
          &quot;source&quot;: &quot;jvm-x994a&quot;,
          &quot;events&quot;: [{               
              &quot;indicator-type&quot;: &quot;memory-low&quot;
            }]
        },
      
        {
          &quot;server&quot;: &quot;10.10.0.202&quot;,
          &quot;date&quot;: 1561994773000,
          &quot;source&quot;: &quot;jvm-x994a&quot;,
          &quot;events&quot;: [{              
              &quot;indicator-type&quot;: &quot;memory-low&quot;
              }
              ]
        }
      
      ]
  </code></pre>
  <p>Expected output:</p>
  <pre><code> List1=[
            {
              &quot;server&quot;: &quot;10.10.0.123&quot;,
              &quot;date&quot;: 1561994754,
              &quot;severity&quot;: &quot;INFO&quot;,
              &quot;process&quot;: &quot;webapp&quot;,
              &quot;message&quot;: &quot;server started.&quot;
            },
            {
              &quot;server&quot;: &quot;10.10.0.202&quot;,
              &quot;date&quot;: 1561994757000,
              &quot;source&quot;: &quot;jvm-x994a&quot;,
              &quot;message&quot;: &quot;memory-low&quot;
                
            },
          
            {
              &quot;server&quot;: &quot;10.10.0.202&quot;,
              &quot;date&quot;: 1561994773000,
              &quot;source&quot;: &quot;jvm-x994a&quot;,
              &quot;message&quot;: &quot;memory-low&quot;
                  }
                  ]
            }
          
          ]
  </code></pre>
  <p>So Far I have Tried :
  In the below code I am trying to check for the &quot;events&quot; key and replacing it with the &quot;message&quot; key, but when I am printing it is not replacing they key-value</p>
  <pre><code>output = []
  d={}
  for x in a:
          d['server']=x['server']
          if (str(x['date']).isdigit() == True):
              d['date'] =2
              # datetime.datetime.fromtimestamp(x['date'] / 1000.0).strftime('%Y-%m-%d %H:%M:%S.%f')
  
          if (&quot;events&quot; in x):
              for i in (x['events']):
                  if (i['indicator-level'] == 3):
                      d['severity'] = &quot;INFO&quot;
                  if (i['indicator-level'] == 7):
                      d['severity'] = &quot;WARN&quot;
                  if (i['indicator-type'] != None):
                      d['message'] = i['indicator-type'] 
  </code></pre>