Python3: unable to import JSONDecodeError from json.decoder

user2349115 picture user2349115 · Jun 23, 2017 · Viewed 13.9k times · Source

I setup virtualenv using python 3.4.3 and tried to import JSONDecodeError from json.decoder

from json.decoder import JSONDecodeError (I think its valid in python3 ? But why not working for me ?) 

But it is not working. Only below is working:

from simplejson import JSONDecodeError

How I did ?

virtualenv venv --no-site-packages -p python3 
pip install ipython
ipython
from json.decoder import JSONDecodeError
ImportError: cannot import name 'JSONDecodeError'

enter image description here

Answer

Łukasz Rogalski picture Łukasz Rogalski · Jun 23, 2017

According to 3.4.x docs, plain ValueError is raised when JSON decoding fails.

JSONDecodeError class is available starting from 3.5.x.