Advertisement
RicardoPirata

JSON Manipulation Python

Jan 27th, 2022
923
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. import json
  2.  
  3. x= {
  4.       "BTC" : {
  5.         "price": 5000
  6.       },
  7.       "ETH" : {
  8.         "price": 1000
  9.       }
  10.     }
  11.  
  12. # convert into JSON:
  13. y = json.dumps(x)
  14. # create a simple JSON array
  15.  
  16.  
  17. # change the JSON string into a JSON object
  18. json_object = json.loads(y)
  19.  
  20. # print the keys and values
  21. for key in json_object:
  22.     value = json_object[key]
  23.     print("The key and value are ({}) = ({})".format(key, value))
  24.  
  25. btc_obj = json_object['BTC']
  26. print(btc_obj["price"])
  27. print(type(obj))
  28. print(obj.items())
  29. #print(json_object['ETH]["price"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement