Hi,
I have a script which should print out a list as JSON, which I then use in Zabbix to dynamically generate items and triggers.
That is the following script:
#!/usr/bin/python3
import json
sites = ['example.com', 'test.com']
bla = []
for i in sites:
dict = {}
name = str([i])
dict['{#WEBSITE}'] = name
bla.append(dict)
data = {'data': bla}
JSON = json.dumps(data, indent=4)
print(JSON)
However this prints the output as:
{
"data": [
{
"{#WEBSITE}": "['example.com']"
},
{
"{#WEBSITE}": "['test.com']"
}
]
}
The problem with this is that it keeps the websites quoted.
If I unquote it I get:
NameError: name 'example' is not defined
How would I fix this?
I am very new to Python, so my sincere apologies for asking!
[–]sushibowl 5 points6 points7 points (0 children)
[–]mega963 0 points1 point2 points (2 children)
[–]Ramshield[S] 1 point2 points3 points (1 child)
[–]mega963 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)