I have written a code to parse and get the values.This is the code:
with open("config.json","r")as infile:
inputs = json.load(infile)
for item in range(len(inputs["config"])):
IP = inputs["config"][item]["IP"]
PORT = inputs["config"][item]["PORT"]
USERNAME = inputs["config"][item]["USERNAME"]
PASSWORD = inputs["config"][item]["PASSWORD"]
ENABLE = inputs["config"][item]["ENABLE"]
if ENABLE == "True":
But, instead of opening a file like this, I would like to pass the json_string as a command line argument so it can read from command line and get the values in json_string to the variables. I have a json_string like this:
{
"cameras": [
{
"ipAddress": "10.27.25.164",
"url": "rtsp://admin:[email protected]/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif",
"userName": "admin",
"userPasswd": "Aviro",
"port": "80"
}
]
}
I would like to know, how to pass json_string as a command line argument and what are the changes i need to modify in the code, so the values in the json_string assigned to the given variables.
can anyone help me with this???
python pass a string as a command line argument site:stackoverflow.comshould get you on your way.