Riju21

39_json_parse

May 12th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. import json
  2.  
  3.  
  4. # more at: https://docs.python.org/3/library/json.html
  5.  
  6. jsonFile = '''{
  7. "people":[
  8.    {
  9.        "name" :"riju",
  10.        "university" : "EWU",
  11.        "progession":"full-stack developer",
  12.        "phone":"0193-7",
  13.        "email":["[email protected]","[email protected]"]
  14.    },
  15.    {
  16.       "name" :"alen",
  17.        "university" : "NSU",
  18.        "progession":"data-scientist",
  19.        "phone":"0188-1",
  20.        "email":null
  21.    }
  22. ]
  23. }
  24. '''
  25. dataLoad = json.loads(jsonFile)
  26. print(dataLoad)
  27. print('\n')
  28.  
  29. # get specific data
  30.  
  31. for people in dataLoad['people']:
  32.     # only email
  33.     print(people['email'])
  34.  
  35.  
  36. print('\n')
  37.  
  38. # 2nd para:to make a nice format,3rd: ascending
  39. dump = json.dumps(dataLoad, indent=2, sort_keys=True)
  40. print(dump)
Advertisement
Add Comment
Please, Sign In to add comment