Don't understand why ValueError: No JSON object could be decoded occurs
<p>I'm getting this following error</p>

<pre class="lang-none prettyprint-override"><code>ValueError: No JSON object could be decoded
</code></pre>

<p>My json data is valid, i changing the JSON file encoding to utf-8, but still didn't work, this is my code :</p>

<pre><code>f = open(os.path.dirname(os.path.abspath(__file__))+"/test.json", 'w+')
data = json.load(f)
pprint(data)
</code></pre>

<p>And this is my test.json data:</p>

<pre><code>{"X":19235, "Y":19220, "Z":22685}
</code></pre>

<p>First of all, let's confirm your json data is valid emulating the content of your file like this:</p>

<pre><code>import json
from StringIO import StringIO

f = StringIO("""

{"X":19235, "Y":19220, "Z":22685}

""")

try:
    data = f.read()
    json.loads(data)
except:
    print("BREAKPOINT")

print("DONE")
</code></pre>

<p>The script is printing only <code>DONE</code>, that means the content of your file is a valid JSON, so if we take a look to your script:</p>

<pre><code>f = open(os.path.dirname(os.path.abspath(__file__))+"/test.json", 'w+')
data = json.load(f)
pprint(data)
</code></pre>

<p>The main problem of your code is you're using <code>w+</code> write mode, which is truncating the file (you should use reading mode) so the file object is not valid anymore. Try this:</p>

<pre><code>f = open(os.path.dirname(os.path.abspath(__file__))+"/test.json", 'rb')
data = json.load(f)
pprint(data)
</code></pre>

<p>or this:</p>

<pre><code>f = open(os.path.dirname(os.path.abspath(__file__))+"/test.json", 'rb')
data = json.loads(f.read())
pprint(data)
</code></pre>

python json object