Python Tutorial: Working with JSON Data using the json Module

///Python Tutorial: Working with JSON Data using the json Module

Python Tutorial: Working with JSON Data using the json Module

FavoriteLoadingAdd to favorites

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

source

By |2019-08-10T21:56:33+00:00August 10th, 2019|Python Video Tutorials|37 Comments

37 Comments

  1. Philip Dinno George August 10, 2019 at 9:56 pm - Reply

    how do we convert a file or say mutliple lists into json messages?

  2. Daniel Cao August 10, 2019 at 9:56 pm - Reply

    when I try to use the json.loads method, I keep getting an error telling me It doesn't accept the type 'dict' any help? thanks

  3. Matías Sandacz August 10, 2019 at 9:56 pm - Reply

    Cristal Clear. Thank you!

  4. Shankar Negi August 10, 2019 at 9:56 pm - Reply

    How to delete if your data type is string not list?

  5. Teru room August 10, 2019 at 9:56 pm - Reply

    わかりやす〜い\(^o^)/。ありがとう(*^^*)。

  6. Christopher Pettersen August 10, 2019 at 9:56 pm - Reply

    How do i access the data in my JSON list if it comes without a key first?

  7. Shashi Bagale August 10, 2019 at 9:56 pm - Reply

    Simply awesome; the way its been explained with clarity & real-time examples. Thanks a lot & Cheers..!!

  8. Firapont August 10, 2019 at 9:56 pm - Reply

    Pure gold!!!!!!

  9. Murtala Isyaku Abdulhamid August 10, 2019 at 9:56 pm - Reply

    Thanks this is great i love the way U explain it. One questions please, as a beginner i am trying to make a python multiple quiz so i save my questions in a python array. So i am finding it difficult to call the question from the json file

  10. Haneul Kim August 10, 2019 at 9:56 pm - Reply

    Thanks for the great video! One question though, so if we want to work with json file in python we must convert whole data into one string?

  11. Raúl Gómez August 10, 2019 at 9:56 pm - Reply

    Hi! I left you an Issue Open for this demo. Hope being of help bro. Link: https://github.com/CoreyMSchafer/code_snippets/issues/58

  12. Jackie Castro August 10, 2019 at 9:56 pm - Reply

    are json files sensitive to indentation?

  13. Andy Johny August 10, 2019 at 9:56 pm - Reply

    Superb..God blesss you

  14. Shirshendu Mukherjee August 10, 2019 at 9:56 pm - Reply

    Thanks, can you suggest how can we compare two json files? And display the difference or unique entry in second file only. I am using version 2.7

  15. H Miri August 10, 2019 at 9:56 pm - Reply

    Hi Corey, Around 13:07 just when you wanna see the response request, I get a bunch of errors that I have no clue what's going on. Do you recognize what the problem might be?

    Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1318, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
    self.connect()
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1400, in connect
    server_hostname=server_hostname)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 407, in wrap_socket
    _context=self, _session=session)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 814, in _init_
    self.do_handshake()
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 1068, in do_handshake
    self._sslobj.do_handshake()
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 689, in do_handshake
    self._sslobj.do_handshake()
    ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/Users/me/PycharmProjects/Draft/app.py", line 4, in <module>
    with urlopen("https://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json&quot😉 as response:
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 526, in open
    response = self._open(req, data)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 544, in _open
    '_open', req)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1361, in https_open
    context=self._context, check_hostname=self._check_hostname)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1320, in do_open
    raise URLError(err)
    urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)>

  16. glowish1993 August 10, 2019 at 9:56 pm - Reply

    Ah, the wonders of YouTube and Corey Schafer. Thank you!

  17. Tumul Sharma August 10, 2019 at 9:56 pm - Reply

    thanks a lot sir !!

  18. Mike August 10, 2019 at 9:56 pm - Reply

    Does that Yahoo Finance link still work today (June 2019)? I couldn't access any data from it 🙁

    https://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json

  19. NO5X August 10, 2019 at 9:56 pm - Reply

    Corey, I tried the following code in yahoo_api.py file:
    import json

    from urllib.request import urlopen

    # URL Open of Yahoo Finance API

    with urlopen("https://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json&quot😉 as response:

    source = response.read()

    print(source)

    And I received a urlllib.error.HTTPError: HTTP Error 502: Server Hangup [Finished in 92.574s]
    Did Yahoo Finance change their API URL for this info? Thanks

  20. Denis Kipkoech August 10, 2019 at 9:56 pm - Reply

    11:16 A brief shit

  21. Narasimha Rao August 10, 2019 at 9:56 pm - Reply

    Very clear and easy to understand, Many thanks.

  22. Ryan Torrie August 10, 2019 at 9:56 pm - Reply

    I honestly don’t give a F about IT or programming anymore, overlords

  23. Python Wonder Woman August 10, 2019 at 9:56 pm - Reply

    <3 love this video! thank you so much, you helped me understand a lot about json and python and resolve issue i had. much appreciated. more videos please 🙂 greetings from Poland 🙂 Py Wonder Woman 🙂

  24. Nima August 10, 2019 at 9:56 pm - Reply

    shit I'm just a pharmacist learning python/pandas to wrangle some health data. Bless you Corey 😉

  25. Josep Mor August 10, 2019 at 9:56 pm - Reply

    Hey, just one question, I'll work on it tomorrow at work. How would this translate to loading the JSON data to models.py to access it from /admin?

  26. Bruno Alves August 10, 2019 at 9:56 pm - Reply

    Thanks for your help!

  27. KV PANKAJ August 10, 2019 at 9:56 pm - Reply

    Anyone getting the extra data error while printing data

  28. Sujan_ np August 10, 2019 at 9:56 pm - Reply

    i am so confused to load on postman api. what i need to do?

  29. Vietnam hoat hinh August 10, 2019 at 9:56 pm - Reply

    thanks kind man

  30. Saket Marodia August 10, 2019 at 9:56 pm - Reply

    Thanks a lot

  31. yash madhav August 10, 2019 at 9:56 pm - Reply

    Hi,

    Can you please tell us how to generate random dictionaries in python ?

  32. Djelari Ghana August 10, 2019 at 9:56 pm - Reply

    JAY-saaannnn…..haha………

  33. Jeff Leigh August 10, 2019 at 9:56 pm - Reply

    Which program are you using to run the json string ?

  34. charles tompkins August 10, 2019 at 9:56 pm - Reply

    Thank-you, Corey for walking us through this. Though it's easy to follow I'm getting an ssl.SSLError in using the Yahoo finance API; probably because I don't have a Rapid API developer account, right? It takes a secured key to open API's in my experience. I think this is the way to access the Yahoo Finance API if I'm not mistaken. https://rapidapi.com/signup

  35. Mustafa Khan August 10, 2019 at 9:56 pm - Reply

    Thank you dear Corey

  36. Sumit Yadav August 10, 2019 at 9:56 pm - Reply

    how to add more keys and values dynamically in JSON by another list?

  37. Magomed Shamaev August 10, 2019 at 9:56 pm - Reply

    Hi! Can't get json data from yahoo financial api from vid. Does anyone know why?

Leave A Comment

*