I have a set of strings formatted as BBB
below, and I need to extract the value corresponding to the text
key (in the example below it's "My life is amazing"
).
BBB = str({
"id": "18976",
"episode_done": False,
"text": "My life is amazing",
"text_candidates": [
"My life is amazing",
"I am worried about global warming"
],
"metrics": {
"clen": AverageMetric(12),
"ctrunc": AverageMetric(0),
"ctrunclen": AverageMetric(0)
}
}
)
I tried converting BBB
into a string and then into a dictionary using json.load
and ast.literal_eval
, but I get error messages in both cases. I suppose this is due to the fact that the metrics
key has a dictionary as a value.
How do you suggest to solve the issue?