Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
checking value on json
#2
not tested but try:

server_type = "server_type2"
 
try:
    data_config = json.load(json_file)
except ValueError:
    logging.critical("Data were not valid json for %s", data_config)
else:
    if server_type not in data_config['server_model'].keys():
        logging.critical("We can not continue: Server type %s not present in config file", server_type)
depending on what you would do further it may be better to try to access data you want with data_config['server_model'].get(server_type) and act accordingly from there
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
checking value on json - by enigma619 - Jan-16-2020, 02:50 PM
RE: checking value on json - by buran - Jan-16-2020, 02:59 PM
RE: checking value on json - by enigma619 - Jan-16-2020, 03:51 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020