Python — JSONDecodeError

A mistake of copy & paste

Tony
3 min readDec 18, 2021

It all started with some scraping. The fun of wrangling through data and making it somewhat useful. After joining and cleaning most of the frames I ended up with something like this:

The last step I had to perform was to map the labels as JSON objects. The steps to do so for me were obvious. A simple replace and a respective map:

dfItem['labels'] = dfItem['labels'].replace("'",'"')
dfItem['labels'] = dfItem['labels'].map(json.loads)

The moment I ran the code block I ended up with the following error:

JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

I thought to myself just like a lot of cryptic pandas errors (I didn’t even bother to read the actual error message), this should be easily solved by a search from google. This copy and paste process led to an ugly vicious circle.

A sequence of reciprocal cause and effect in which two or more elements intensify and aggravate each other, leading inexorably to a worsening of the situation.

Every solution I could find was a mix of regex and replace functions. If you don’t believe me check for yourself:

--

--

Tony

contact me for any Data Science or Data Engineering consultations on tonycini93@hotmail.com