How to create a JSON object in Python

Hi, I need to create a JSON object in the following format. How to do it

{"user2_proximity": 3, "Wifi_1": -80, "Wifi_2": -40, "Wifi_3": -40, 
"thermostat": 18, "light": 0, "hour_of_day": 0, "user3_proximity": 3, 
"user1_proximity": 1, "day_of_week": 1, "security": 0, "minute_of_hour": 9, 
"Act_1": 1, "Act_2": 0, "Act_3": 0}
+4
source share
1 answer

source: https://docs.python.org/2/library/json.html

import json
data = {"user2_proximity": 3, "Wifi_1": -80, "Wifi_2": -40, "Wifi_3": -40, 
"thermostat": 18, "light": 0, "hour_of_day": 0, "user3_proximity": 3, 
"user1_proximity": 1, "day_of_week": 1, "security": 0, "minute_of_hour": 9, 
"Act_1": 1, "Act_2": 0, "Act_3": 0}

json_data = json.dumps(data)
+13
source

Source: https://habr.com/ru/post/1666216/


All Articles