Reputation: 321
I'm trying to convert a string to a dictionary but I keep getting this error:
ValueError: dictionary update sequence element #0 has length 1; 2 is required
Here's my code:
string = r'{"extra":[{"text":"Hello World"}]}'
json_data = dict(string)
Upvotes: 0
Views: 643
Reputation: 442
I believe you are looking for:
import json
string = r'{"extra":[{"text":"Hello World"}]}'
json_data = json.loads(string)
There are a few JSON parsing libraries. Default one should suffice, simplejson is another option (just to give you an alternative).
Upvotes: 2