I have a complex string with a nested dictionary in it. This dictionary further has a list of three similar dictionaries inside it. How do I convert this into a Python dictionary? Please help.
Input: 'name: "data dict" id: 2\nv6: false\nstats {\n hosts {\n cnt1: 256\n cnt2: 0\n }\n groups {\n cnt1: 1\n cnt2: 0\n }\n main_groups {\n cnt1: 1\n cnt2: 0\n }\n main_hosts {\n cnt1: 256\n cnt2: 0\n }\n}\n group_id: "None"'
Expected result: {
name: "data dict",
id: 2,
v6: false,
stats: {
hosts: {
cnt: 1, cnt: 2
}
groups: {
cnt: 1, cnt: 2
}
main: {
cnt: 1, cnt: 2
}
main_hosts: {
cnt: 1, cnt: 2
}
}
}
regex. I'm a fan ofpyparsingfor tasks like this.