title: How to remove white spaces and \n in the JSON file in Python
body: <p>I have JSON data coming to S3 in the format:</p>
  <pre><code>{\n  \&quot;data\&quot;: {\n    \&quot;event_type\&quot;: \&quot;message.received\&quot;,\n    \&quot;id\&quot;: \&quot;819\&quot;,\n    \&quot;occurred_at\&quot;: \&quot;2020-10\&quot;,\n    \&quot;payload\&quot;: {\n      \&quot;cc\&quot;: [],\n      \&quot;completed_at\&quot;: null,\n      \&quot;cost\&quot;: null,\n      \&quot;direction\&quot;: \&quot;inbound\&quot;,\n      \&quot;encoding\&quot;: \&quot;GSM-7\&quot;,\n      \&quot;errors\&quot;: [],\n      \&quot;from\&quot;: {\n        \&quot;carrier\&quot;: \&quot;Verizon\&quot;,\n        \&quot;line_type\&quot;: \&quot;Wireless\&quot;,\n        \&quot;phone_number\&quot;: \&quot;+111111111\&quot;\n      },\n      \&quot;id\&quot;: \&quot;e8e0d1e3-dce3-\&quot;,\n      \&quot;media\&quot;: [],\n      \&quot;messaging_profile_id\&quot;: \&quot;400176\&quot;,\n      \&quot;organization_id\&quot;: \&quot;717d556f-ba4f-\&quot;,\n      \&quot;parts\&quot;: 1,\n      \&quot;received_at\&quot;: \&quot;2020-1\&quot;,\n      \&quot;record_type\&quot;: \&quot;message\&quot;,\n      \&quot;sent_at\&quot;: null,\n      \&quot;tags\&quot;: [],\n      \&quot;text\&quot;: \&quot;Hi \&quot;,\n      \&quot;to\&quot;: [\n        {\n          \&quot;carrier\&quot;: \&quot;carr\&quot;,\n          \&quot;line_type\&quot;: \&quot;Wireless\&quot;,\n          \&quot;phone_number\&quot;: \&quot;+111111111\&quot;,\n}\n}&quot;
  </code></pre>
  <p>I want it to be converted like this:</p>
  <pre><code>{
    &quot;data&quot;: {
      &quot;event_type&quot;: &quot;message.received&quot;,
      &quot;id&quot;: &quot;76a60230&quot;,
      &quot;occurred_at&quot;: &quot;2020-12-1&quot;,
      &quot;payload&quot;: {
        &quot;cc&quot;: [],
        &quot;completed_at&quot;: null,
        &quot;cost&quot;: null,
        &quot;direction&quot;: &quot;inbound&quot;,
        &quot;encoding&quot;: &quot;GSM-7&quot;,
        &quot;errors&quot;: [],
        &quot;from&quot;: {
          &quot;carrier&quot;: &quot;Verizon&quot;,
          &quot;line_type&quot;: &quot;Wireless&quot;,
          &quot;phone_number&quot;: &quot;+1111111111&quot;
        },
        &quot;id&quot;: &quot;06c9c765&quot;,
        &quot;media&quot;: [],
        &quot;messaging_profile_id&quot;: &quot;40017&quot;,
        &quot;organization_id&quot;: &quot;717d5&quot;,
        &quot;parts&quot;: 1,
        &quot;received_at&quot;: &quot;2020-1&quot;,
        &quot;record_type&quot;: &quot;message&quot;,
        &quot;sent_at&quot;: null,
        &quot;tags&quot;: [],
        &quot;text&quot;: &quot;Hi&quot;,
        &quot;to&quot;: [
          {
            &quot;carrier&quot;: &quot;abc&quot;,
            &quot;line_type&quot;: &quot;Wireless&quot;,
            &quot;phone_number&quot;: &quot;+1111111111&quot;,
            &quot;status&quot;: &quot;delivered&quot;
          }
        ],
        &quot;type&quot;: &quot;SMS&quot;,
        &quot;valid_until&quot;: null,
        &quot;failover_url&quot;: null,
        &quot;url&quot;: &quot;https://639hpj&quot;
      },
      &quot;record_type&quot;: &quot;event&quot;
    },
    &quot;meta&quot;: {
      &quot;attempt&quot;: 1,
      &quot;delivered_to&quot;: &quot;https://639hpj&quot;
    }
  }
  </code></pre>
  <p>The first JSON data I kept came in lines and not in the Struct format. I did not keep the actual JSON data but it was in that similar format (but valid). I would like to run a lambda function in which the JSON data is free from <code>\n</code> and white spaces.</p>
  <p>The above 2 JSON data are not the same but I will be receiving the first type of JSON data and I would like to convert it to the second type which is free of white spaces and <code>\n</code>.</p>