Python Tutorial: Working with JSON Data using the json Module



In this Python Programming Tutorial, we will be learning how to work with JSON data. We will learn how to load JSON into Python objects from strings and how to convert Python objects into JSON strings. We will also see how to load JSON from a file and save those Python objects back to files. Let’s get started…

The code from this video can be found at:

Python File Objects:

✅ Support My Channel Through Patreon:

✅ Become a Channel Member:

✅ One-Time Contribution Through PayPal:

✅ Cryptocurrency Donations:
Bitcoin Wallet – 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet – 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet – MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey’s Public Amazon Wishlist

✅ Equipment I Use and Books I Recommend:

▶️ You Can Find Me On:
My Website –
My Second Channel –
Facebook –
Twitter –
Instagram –

#Python

Nguồn: https://benjaminjcohen.com/

Xem thêm bài viết khác: https://benjaminjcohen.com/cong-nghe/

38 Comments

  1. Great tutorial. Just be sure you don't name your example python code file "json.py"… 🙂

  2. Thanks Bro….Jajakalla Khairan

  3. can we open by, f = open('states.json') ?

  4. Hi there, Thanks for your truly amazing video.
    Do you know how we can POST images into json data without saving them but just reading?

  5. The concept on the currency json is great, but unfortunately, this example will no longer work, as Yahoo has pulled this down. There is a big "me too" movement with many companies requiring api keys, as part of a paid, subscription service. All good things must come to an end.

  6. I was struggling with this for the past 3 days, thank you so much for your video tutorials, they really helped me.

  7. The best youtube channel! Thank you so much Corey!

  8. I didn't understand the thing, you write the JSON code then convert it into python-format.
    Can anybody explain to me, what is the work of JSON and why do we use it?

  9. Can someone tell me what is going on and how to fix this error: Exception has occurred: JSONDecodeError

    Expecting ',' delimiter: line 4 column 14 (char 36)

  10. to all the haters in here, can you give me one reason why you hate such clear and to the point content? @Corey, I love all your videos man.

  11. 😅CAN'T PRAISE YOU ON EVERY VIDEO OF YOURS….BUT YOU MAKE ME DO IT.
    Watched it first time and understood 100%

  12. Thank you sooo much Corey!!
    You have made my journey of self learning python a hell lot easier and interesting.😃
    Again can't thank you enough!!!😊

  13. when i try to run the first one i get nothing

  14. I searched for a specific part in the video and skipped through like 4/5 times. Everytime the video started playing at the other location you said the word "access" haha
    Your videos are awesome btw

  15. simple ,crisp and clear explanation. Thank you very much for your very precise examples which will register in mind

  16. Awesome video. 12:31 For those that need a supplement to the outdated Yahoo API – try this site https://jsonplaceholder.typicode.com/. Also 8:14 as illustrated at 13:30 another way you can get the JSON to a workable str is by using 'json.loads(some_file.read())' but the .load method is preferred and 1 less step. Just thought I would mention that for anyone who has watched Corey's videos about working with File Objects and curious about why the .loads won't work on the Valid-JSON without the .read

  17. In general is it best use to a json configuration file over a python secrets. py file to setup a project?
    Let me know if you need more information or are confused by how I asked this

  18. This is a damn good video. It looks like you've just shown me exactly what I needed to know. I'd been hunting around for a while using Google… And thought I'd do a search on YouTube and this was the 2nd video on this topic I watched. Thanks heaps!!!

  19. It seems the yahoo link is no longer available.

  20. Hey, anybody know how to create and add items to a file like this?
    {
    "zones": [
    "river.com",
    "stream.com"
    ]
    }

  21. How would you take this outputed data from the api website and put it in a Sqlite table

  22. This is the most amazing explanation I've seen so far 🙂

  23. looks like this api is not available anymore??

  24. You are the best python teacher ever. Every single time I go through documentation to learn something, I feel confused. Every single time I type on youtube my problem, one of your videos shows up and I understand everything completely. You are a wonderful teacher. Thank you for your time!

  25. Thanks for this video. Simplest explaination.

  26. Corey, you are amazing! Thank you for your time and most of all, your being you, a person who has a good heart of sharing your knowledge. Your content shows your maturity in your field of expertise. More power to you!

  27. How to use the open Trivia Api in python if we want only one time show one questions

  28. Very straightforward, helpful videos for the python beginner. Thanks!

  29. Lets say if i have a test data where it tells me 'pass' and 'fail' how do i print all the 'pass' cases only? also lets say I have time as to how long they took to write the test. How do i print all the test that took longer than lets 10 minutes?

  30. Thanks! Great tutorial on json and practical json API example.

    However, @18:17 Corey said, "…You could see this says that a USD is equal to about 0.8465 Euros…". It's rather the other way round as the EUR is the denominator there. Similarly, there are errors @18:55 and @19:12 while demonstrating conversion of 50 USD to Euro and Indian Rupees, respectively, instead of what it should have been, 50 Euros and 50 Indian Rupees to USD.

    Also, @ 11:19 he said the command he'd run earlier deleted the phone number but it was the area_codes. The phone number deletion was for the people json at the beginning of the video. Not a big deal but minor errors, that can be corrected with text overlays on the video. Still, hands down, an excellent tutorial on json for beginners.

  31. the URL for currencies api is no longer valied. Do you have a new URL?

  32. Excellen video, I have question. I have the following statement but after the colon there are missing info. I cannot put in the field name if I do that then I get an error indicating that it needs to be an integer. The value after the data does not display even though i have the index. Within the extras:{
    data: 1
    data: 2
    data: 3
    }
    for item in data['extras']:
    name = item[0:]
    print(name)

  33. can somebody explain what dump and dumps actually do?(in english) when corey deleted a key with its value he printed that with dumps .but i just printed the data and the output is same :"(

  34. Thank you very much for your excellent tutorial, well structured, solved the problem immediately

Leave a Reply

Your email address will not be published. Required fields are marked *