Reputation: 29
ip_adrs_ve100_lst = ['5.5.5.1', '5.5.5.2']
at_ip_1 = '10.10.10.1'
at_ip_2 = '10.10.10.2'
to json format.
Upvotes: 2
Views: 12429
Reputation: 174624
Just create a dictionary, and then convert it to json:
data_dict = {'ip_adrs_ve100_lst': ['5.5.5.1', '5.5.5.2'],
'at_ip_1': '10.10.10.1',
'at_ip_2': '10.10.10.2'}
import json
to_json = json.dumps(data_dict)
Upvotes: 3
Reputation: 2500
Just to mention, add ensure_ascii=False
to json.dumps()
call to ensure that the returned instance is always unicode
:
import json
my_dict = {
'ip_adrs_ve100_lst': ['5.5.5.1', '5.5.5.2'],
'at_ip_1': '10.10.10.1',
'at_ip_2': '10.10.10.2'
}
my_json = json.dumps(my_dict, ensure_ascii=False)
Upvotes: 1