Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ['.Attributes[2]']['bestTime'] => Jun 25, 2018 6:00:00 AM
- ['Attributes'][2]['bestTime'] => Jun 25, 2018 6:00:00 AM
- str = {"lAttributes":[{"Identifier":{"newIdentifier":{"DDline":"BM","guideIdDate":"Jun 25, 2018 12:00:00 AM","guideNo":"MM","suffix":"A"},"origin":"FRY","destination":"DZ"},"guideOwner":"VX","guideRegistration":"DD","guideType":"44","bestaartureStatus":"S","bestaaTime":"Jun 25, 2018 6:00:00 AM","bestaaStatus":"S","bestaartureTime":"Jun 25, 2018 5:00:00 AM","compartments":[{"code":"DD","guideCapacity":8,"guideBooked":0,"guideForecast":0},{"code":"DD","guideCapacity":10,"guideBooked":0,"guideForecast":0},{"code":"DD","guideCapacity":32,"guideBooked":0,"guideForecast":0},{"code":"DD","guideCapacity":24,"guideBooked":0,"guideForecast":0}]}]}
- list_k = ['w','r']
- def traverse(path, str):
- count = -1
- if isinstance(str, dict):
- d = str
- for k, v in d.items():
- if isinstance(v, dict):
- traverse(path + "." + k, v)
- elif isinstance(v, list):
- traverse(path + "." + k, v)
- else:
- if k in list_k:
- print("['"+path +"']"+ "['"+k+"']", "=>", v)
- if isinstance(str, list):
- li = str
- for e in li:
- count += 1
- if isinstance(e, dict):
- traverse("{path}[{count}]".format(path=path, count=count), e)
- elif isinstance(e, list):
- traverse("{path}[{count}]".format(path=path, count=count), e)
- else:
- print("[{path}][{count}] => {e}".format(path=path, count=count, e=e))
Add Comment
Please, Sign In to add comment