python json load SortedDict

54 Views Asked by At

I have this string

sorted_dict = '{"state": SortedDict([("a", 1), ("b", 2), ("c", 3)])}'

I need to parse

Try:

mjl = json.loads(sorted_dict, object_pairs_hook=OrderedDict )

but I have this error

JSONDecodeError: Expecting value: line 1 column 11 (char 10)

1

There are 1 best solutions below

0
On

This is not valid JSON. If you get it like this, and you have no other way to parse it, you could always use eval, but keep in mind that it is risky if you use user input:

from module import SortedDict

...

mjl = eval(sorted_dict)