-4

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?

sub123
  • 1
  • 1

1 Answers1

0

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}]
Jeril
  • 7,858
  • 3
  • 52
  • 69