'python string to list (in string and json) [duplicate]
I want to convert these strings to a list. in python
from
42["pause",{"all":false,"media_only":false,"media_exclude":false}]
(type : string)
to["pause",{"all":false,"media_only":false,"media_exclude":false}]
(type : list (in string and json))
There is a way to parse the string directly, but since the types of incoming data are various, I was looking for a function that can be converted directly, but I couldn't find it. How can I do that?
Solution 1:[1]
Can you try the following:
import json
text = '''42["pause",{"all":false,"media_only":false,"media_exclude":false}]'''
text = text[text.find('['):]
result = json.loads(text)
print(result)
Output:
['pause', {'all': False, 'media_only': False, 'media_exclude': False}]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jeril |
