Skip to content

Instantly share code, notes, and snippets.

@asvetlov
Created May 23, 2018 09:42
Show Gist options
  • Save asvetlov/fd3213720b03a144e0e1465ea02064cf to your computer and use it in GitHub Desktop.
Save asvetlov/fd3213720b03a144e0e1465ea02064cf to your computer and use it in GitHub Desktop.
import json
import re
s = """new APIData([
new APIControllers([
new APIProp({name:"durable-id",value:"controller_a"}),
new APIProp({name:"controller-id",value:"A"}),
new APIProp({name:"controller-id-numeric",value:"1"}),
new APIProp({name:"serial-number",value:"CN8415M489"})
])
])"""
s2 = re.sub("new API[A-Za-z]+", "", s)
s3 = s2.replace('(', '')
s4 = s3.replace(')', '')
s5 = re.sub("([a-z]+):", r'"\1":', s4)
ret = json.loads(s5)
print(ret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment