Combreal

iterateThroughJson.py

Jul 29th, 2021 (edited)
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  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))
Add Comment
Please, Sign In to add comment