rodrigosantosbr

[Py] Json - Parsing JSON

Feb 16th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. # https://repl.it/languages/python3
  2.  
  3. import json
  4.  
  5. data = '''
  6. [
  7.  { "id" : "001",
  8.    "x" : "2",
  9.    "name" : "Chuck"
  10.  } ,
  11.  { "id" : "009",
  12.    "x" : "7",
  13.    "name" : "Brent"
  14.  }
  15. ]
  16. '''
  17.  
  18. info = json.loads(data)
  19. print('User count:', len(info))
  20.  
  21. # what we get from json.loads() is a Python list which we traverse with
  22. # a for loop, and each item within that list is a Python dictionary.
  23.  
  24. for item in info:
  25.   print('-Name', item['name'])
  26.   print('-Id', item['id'])
  27.   print('-x', item['x'])
Advertisement
Add Comment
Please, Sign In to add comment