Michele Mancini
Michele Mancini

Reputation: 41

python json load SortedDict

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)

Upvotes: 0

Views: 53

Answers (1)

Xiddoc
Xiddoc

Reputation: 3619

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)

Upvotes: 1

Related Questions