title: Python: Sanitize data in JSON before sending
body: <p>I have a JSON file that needs to be sent. Before sending I need to do a validity check and replace some special characters (spaces and dots(<code>.</code>)).</p>
  
  <p>The problem is that Python inserts <code>u</code> character before each of my strings, which can't be read by the server. How do I remove the <code>u</code> character and do the data sanitation (character replacement)?</p>
  
  <p>Original JSON</p>
  
  <pre><code>{
      "columns": [
          {
              "data": "Doc.",
              "title": "Doc."
          },
          {
              "data": "Order no.",
              "title": "Order no."
          },
          {
              "data": "Nothing",
              "title": "Nothing"
          }
      ],
      "data": [
          {
              "Doc.": "564251422",
              "Nothing": 0.0,
              "Order no.": "56421"
          },
          {
              "Doc.": "546546545",
              "Nothing": 0.0,
              "Order no.": "98745"
          }
      ]
  }
  </code></pre>
  
  <p>Python:</p>
  
  <pre><code>import json
  def func():
      with open('json/simpledata.json', 'r') as json_file:
          json_data = json.load(json_file)
          print(json_data)
  func()
  </code></pre>
  
  <p>Output JSON:</p>
  
  <pre><code>{u'data': [{u'Nothing': 0.0, u'Order no.': u'56421', u'Doc.': u'564251422'}, {u'Nothing': 0.0, u'Order no.': u'98745', u'Doc.': u'546546545'}], u'columns': [{u'data': u'Doc.', u'title': u'Doc.'}, {u'data': u'Order no.', u'title': u'Order no.'}, {u'data': u'Nothing', u'title': u'Nothing'}]}
  </code></pre>
  
  <p>What I'm trying to achieve in Python:</p>
  
  <pre><code>    sanitizeData: function(jsonArray) {
          var newKey;
          jsonArray.forEach(function(item) {
              for (key in item) {
                  newKey = key.replace(/\s/g, '').replace(/\./g, '');
                  if (key != newKey) {
                      item[newKey] = item[key];
                      delete item[key];
                  }
              }
          })
          return jsonArray;
      },
      # remove whitespace and dots from data : &lt;propName&gt; references
      sanitizeColumns: function(jsonArray) {
          var dataProp = [];
          jsonArray.forEach(function(item) {
              dataProp = item['data'].replace(/\s/g, '').replace(/\./g, '');
              item['data'] = dataProp;
          })
          return jsonArray;
      }
  </code></pre>