I'm trying to parse the test_string
to JSON but failing, just continues as string after json.dumps
, see result below. How can I get the expected output?
The test_string
is pulled from a text object and that's how it's quoted.
test_string = "{'fruit': ['Yes'], 'vegetables': ['carrot']}"
# output
json.dumps(test)
'"{\'fruit\': [\'Yes\'], \'vegetables\': [\'carrot\']}"'
# expected output
{'fruit': ['Yes'], 'vegetables': ['carrot']}
json.loads
?json.dumps
is for creating a string from a python object. Though I don't thing yourtest_string
will parse as JSON wants double quotes.json.loads
gives a decoding error.ast.literal_eval
workedjson.loads
fails