I ask advice. I need to create a JSON object with the same keys. This is necessary to send a request to zabbix for host.create . https://www.zabbix.com/documentation/3.0/ru/manual/api/reference/host/create If you specify more than one group, it accepts only
{"groupid": "2", "groupid": "8"}
Does not understand:
{"groupid": ["2","8"]}
I suppose to use a structure.
[("groupid","2"),("groupid","8")]
I solved the problem in this way, but I do not understand how to convert to JSON, because the keys are not strings
import json
from json import JSONEncoder
class SameKeys(JSONEncoder):
def __init__(self, name):
self.name = name
def __repr__(self):
return json.dumps(self.name)
data = [("groupid", "2"), ("groupid", "8")]
a = {SameKeys("groupid"): "2", SameKeys("groupid"): "8"}
print(a)
But I can not understand how to do it better so as not to make crutches, there may already be a ready solution, but having spent time I did not find anything suitable. Thank you for any advice