Combreal

iterateThroughJson.py

Jul 29th, 2021 (edited)
161
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import requests
  2. import json
  3. import sys
  4.  
  5. dataJson = '{"id":"file","value":"File","popup":{"menuitem":[{"value":"New","onclick":"CreateNewDoc()"},{"value":"Open","onclick":"OpenDoc()"},{"value":"Close","onclick":"CloseDoc()"}]}}'
  6.  
  7. data = json.loads(dataJson)
  8.  
  9. for item in data["popup"]["menuitem"]:
  10.    print(item.get('onclick'))
  11.  
  12.  
  13. #json compacter : https://jsonformatter.org/e8391c
  14. #pretty print json : print(json.dumps(data, indent=4, sort_keys=True))
RAW Paste Data