Created
September 23, 2018 22:16
-
-
Save pknowledge/1e11a88ac3bc1dce09cc12a37951c0d1 to your computer and use it in GitHub Desktop.
Python Tutorial for Beginners 43 - Working With JSON Data in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
print(json.dumps({"name": "max", "age": 22})) | |
print(json.dumps(["1", "2"])) | |
print(json.dumps(("1", "2"))) | |
print(json.dumps("Hello World")) | |
print(json.dumps(100)) | |
print(json.dumps(15.56)) | |
print(json.dumps(False)) | |
print(json.dumps(True)) | |
print(json.dumps(None)) | |
a = { | |
'name': 'max', | |
'age': 22, | |
'marks': [90, 50, 80, 40], | |
'pass': True, | |
'object': { | |
'color':('red', 'blue') | |
} | |
} | |
with open('demo.json', 'w') as fh: | |
fh.write(json.dumps(a, indent=2)) | |
with open('demo.json', 'r') as fh: | |
json_str = fh.read() | |
json_value = json.loads(json_str) | |
print(type(json_value)) | |
print(json_value['name']) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment