JSON data:
new_dto_data = [{'DeviceInstanceId': 24, 'IsResetNeeded': False, 'ProductType': 'SLDW', 'Product': {'Family': 'SL DW'}, 'Device': {'DeviceFirmwareUpdate': {'DeviceUpdateStatus': None, 'DeviceUpdateInProgress': None, 'DeviceUpdateProgress': None, 'LastDeviceUpdateId': None}, 'ManualAdded': False, 'Name': {'DeviceName': 'SLDW25', 'IsUnique': False}, 'State': 0, 'Location': 'Room'}]
My script:
def test():
"""Validate that the 0 or more Payload dicts in record
use proper types"""
err_path = "root"
try:
for record in new_dto_data:
device = record["Device"]
key_data = ((device["ManualAdded"], bool), (device["State"], int),(device["Location"], (str, type(None)))
for i in key_data:
if not isinstance(*i):
return False
except KeyError as err_path:
print("missing key")
return False
return True
print(test())
If I get response "False" then I should print which key it got response "False".
Script should not stop if I get response "False". It should run until end of the loop and print all keys which got "False" response.
Currently I am getting response "False" but not able to find out which key and script is stopping once I get "False".