title: Python ValueError: No JSON object could be decoded even though the JSON is valid
body: <p>I have a valid JSON file (verified with <a href="https://jsonlint.com/" rel="nofollow noreferrer">this</a> website) that all of sudden can't be read.</p>
  <p>This script has been working since forever. I'm not sure what changed.</p>
  <p>This is the script:</p>
  <pre class="lang-py prettyprint-override"><code>import os
  import json
  
  basepath = '/path/'
  for entry in os.listdir(basepath):
      if os.path.isfile(os.path.join(basepath, entry)):
          with open(&quot;{}/{}&quot;.format(basepath, entry), 'r') as myfile:
              data=myfile.read()
  
          obj = json.loads(data)
          if obj.get('enabled'):
              print(&quot;test&quot;)
  </code></pre>
  <p>This is the full error:</p>
  <pre><code>File &quot;src/utils/process_utils.py&quot;, line 34, in invoke
      raise ExecutionException(result_code, error, output)
  utils.process_utils.ExecutionException: Execution failed. Code 1: Traceback (most recent call last):
    File &quot;conf/scripts/script.py&quot;, line 12, in &lt;module&gt;
      obj = json.loads(data)
    File &quot;/usr/lib64/python2.7/json/__init__.py&quot;, line 339, in loads
      return _default_decoder.decode(s)
    File &quot;/usr/lib64/python2.7/json/decoder.py&quot;, line 364, in decode
      obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    File &quot;/usr/lib64/python2.7/json/decoder.py&quot;, line 382, in raw_decode
      raise ValueError(&quot;No JSON object could be decoded&quot;)
  ValueError: No JSON object could be decoded
  </code></pre>
  <p>I use <code>read()</code> and <code>loads</code> to make sure everything is a string. Looking for ideas on what could have changed, because this script has been working since forever and it's automated.</p>
  <p>Edit:</p>
  <p>Just tried without <code>read()</code>. Just <code>json.load</code> and it gives the same output.</p>
  <p>Edit2:</p>
  <p>An example for the JSON file:</p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;id&quot;: 1234567,
      &quot;login&quot;: &quot;jsmith&quot;,
      &quot;name&quot;: &quot;John Smith&quot;,
      &quot;first_name&quot;: &quot;John&quot;,
       ...
       ...
  }
  </code></pre>
  <p>The rest of the file just looks the same, more parameters about users.</p>
  <p><code>find . -not -name &quot;*.json&quot;</code> didn't find non-JSON files.</p>
  <p>printing the <code>data</code> variable:</p>
  <pre><code>John Smith (jsmith)
  {
      &quot;department_number&quot;: 123,
      &quot;department_name&quot;: &quot;Department&quot;,
      &quot;anpa_dep&quot;: &quot;Dep&quot;,
      &quot;requester&quot;: nul
  }
  
  Traceback (most recent call last):
    File &quot;conf/scripts/script-server_anpa_users.py&quot;, line 13, in &lt;module&gt;
      obj = json.loads(data)
    File &quot;/usr/lib64/python2.7/json/__init__.py&quot;, line 339, in loads
      return _default_decoder.decode(s)
    File &quot;/usr/lib64/python2.7/json/decoder.py&quot;, line 364, in decode
      obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    File &quot;/usr/lib64/python2.7/json/decoder.py&quot;, line 382, in raw_decode
      raise ValueError(&quot;No JSON object could be decoded&quot;)
  ValueError: No JSON object could be decoded
  </code></pre>
  <p>the <code>&quot;requester&quot;: nul</code> looks weird. Gonna try to remove that specific json.</p>