Reputation: 155
In python3, Can you please help convert the dictionary values that is a long string into a list:
d1 =
{'result': '[{"pod_name": "kafka-9", "resolution_ms": 60000, "value": 420.85},
{"pod_name": "kafka-3", "resolution_ms": 60000, "value": 418.0}]'...}
The dict values is a string, not a list as it should be , how can I conver the dictionary into a list like
res =
{'result': [{"pod_name": "kafka-9", "resolution_ms": 60000, "value": 420.85},
{"pod_name": "kafka-3", "resolution_ms": 60000, "value": 418.0}]...}
Upvotes: 1
Views: 75
Reputation: 1986
Try this; using json
import json
df1 = {'result': '[{"pod_name": "kafka-9", "resolution_ms": 60000, "value": 420.85},{"pod_name": "kafka-3", "resolution_ms": 60000, "value": 418.0}]'}
result = [json.loads(idx.replace("'", '"')) for idx in [df1['result']]]
df1['result'] = result[0]
# Output of df1;
{'result': [{'pod_name': 'kafka-9', 'resolution_ms': 60000, 'value': 420.85},
{'pod_name': 'kafka-3', 'resolution_ms': 60000, 'value': 418.0}]}
Upvotes: 1