1

I am trying to load JSON into a python dict:

>>> d
'[{"amount":"0","categories":["test","test2","test3"],"categoryIds":["A001G001","A003E001A001","A003G002A001","A003T001A001"]}]'

Unfortunatelly I do get an error message which I could not get around:

>>> json.loads(d, strict=False)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 361, in loads
    return cls(**kw).decode(s)
  File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Invalid \escape: line 1 column 410 (char 409)

How can I load the JSON into a python dictionary?

Ismael Padilla
  • 5,246
  • 4
  • 23
  • 35
merlin
  • 2,717
  • 3
  • 29
  • 59
  • You simplified the code too much that it no longer creates the error; nevertheless it's a duplicate of [python - simplejson.loads() get Invalid \escape: 'x' - Stack Overflow](https://stackoverflow.com/questions/4296041/simplejson-loads-get-invalid-escape-x?noredirect=1&lq=1) – user202729 Feb 17 '21 at 11:49

1 Answers1

1

There is an object within the json:

{"amount":"0","categories":["Gereizte Haut","Gesichtspflege f\xFCr allergische Haut","Insektenstiche","Sonnenallergie & Mallorca-Akne","Basispflege & Reinigung"],"categoryIds":["A001G002","HN001A002G001","HN001A002I002","HN001A002S001","HN001N001B001"],"name":"Linola akut 0,5% Creme","price":969,"pzn":"02138990"}

with the string: "Gesichtspflege f\xFCr allergische Haut" which is not valid json.

You need to get your source to encode the data properly.

quamrana
  • 37,849
  • 12
  • 53
  • 71