Created
November 6, 2018 15:53
-
-
Save zeddee/e3bc18541cd63d11006b7ecacf0c00bf to your computer and use it in GitHub Desktop.
manipulating json with python
This file contains hidden or 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
{ | |
"article": [ | |
{ | |
"id":"01", | |
"language": "JSON", | |
"edition": "first", | |
"author": "Derrick Mwiti" | |
}, | |
{ | |
"id":"02", | |
"language": "Python", | |
"edition": "second", | |
"author": "Derrick Mwiti" | |
} | |
], | |
"blog":[ | |
{ | |
"name": "Datacamp", | |
"URL":"datacamp.com" | |
} | |
] | |
} |
This file contains hidden or 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 | |
with open("./data.json","r") as f: | |
#o = f.read() | |
jsondata = json.load(f) | |
output = jsondata["blog"] | |
print(output) | |
jsonObj = { | |
"url": "datacamp.com", | |
"name": "datacamp" | |
} | |
with open("./jsondump.json","w") as f: | |
f.write(json.dumps(jsonObj)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment