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

description
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: https://github.com/CoreyMSchafer/code_snippets/tree/master/Python-JSON Python File Objects: https://youtu.be/Uh2ebFW8OYM ✅ Support My Channel Through Patreon: https://www.patreon.com/coreyms ✅ Become a Channel Member: https://www.youtube.com/channel/UCCezIgC97PvUuR4_gbFUs5g/join ✅ One-Time Contribution Through PayPal: https://goo.gl/649HFY ✅ Cryptocurrency Donations: Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3 Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33 Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot ✅ Corey's Public Amazon Wishlist http://a.co/inIyro1 ✅ Equipment I Use and Books I Recommend: https://www.amazon.com/shop/coreyschafer ▶️ You Can Find Me On: My Website - http://coreyms.com/ My Second Channel - https://www.youtube.com/c/coreymschafer Facebook - https://www.facebook.com/CoreyMSchafer Twitter - https://twitter.com/CoreyMSchafer Instagram - https://www.instagram.com/coreymschafer/ #Python

detail
{'title': 'Python Tutorial: Working with JSON Data using the json Module', 'heatmap': [{'end': 132.687, 'start': 65.447, 'weight': 0.84}, {'end': 272.814, 'start': 184.822, 'weight': 0.874}, {'end': 451.238, 'start': 430.822, 'weight': 0.736}, {'end': 534.147, 'start': 503.006, 'weight': 0.794}, {'end': 666.978, 'start': 652.966, 'weight': 0.85}, {'end': 704.76, 'start': 685.609, 'weight': 0.715}, {'end': 931.129, 'start': 899.953, 'weight': 0.714}], 'summary': 'The tutorial covers basics of working with json data in python, loading & converting json data, working with json files, parsing json strings & files, and understanding json data structure. it also demonstrates currency conversions with examples.', 'chapters': [{'end': 78.439, 'segs': [{'end': 31.892, 'src': 'embed', 'start': 0.269, 'weight': 0, 'content': [{'end': 0.89, 'text': "hey there, how's it going?", 'start': 0.269, 'duration': 0.621}, {'end': 4.772, 'text': "everybody in this video we'll be learning how to work with json data in python.", 'start': 0.89, 'duration': 3.882}, {'end': 6.093, 'text': "now, if you've never used json.", 'start': 4.772, 'duration': 1.321}, {'end': 12.417, 'text': "basically it's a very common data format for storing some information and you're bound to run into this at some point if you haven't already.", 'start': 6.093, 'duration': 6.324}, {'end': 16.279, 'text': "so you'll see json used a lot when fetching data from online apis,", 'start': 12.417, 'duration': 3.862}, {'end': 21.763, 'text': "but it's also used for configuration files and different kinds of data that can be saved on your local machine.", 'start': 16.279, 'duration': 5.484}, {'end': 25.385, 'text': 'so json stands for javascript object notation.', 'start': 21.763, 'duration': 3.622}, {'end': 27.707, 'text': "but don't get caught up on the javascript part of the name.", 'start': 25.385, 'duration': 2.322}, {'end': 31.892, 'text': 'It was inspired by JavaScript but is now independent of any one language.', 'start': 28.127, 'duration': 3.765}], 'summary': 'Learn to work with json data in python, a common data format for apis and local storage.', 'duration': 31.623, 'max_score': 0.269, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9N6a-VLBa2I/pics/9N6a-VLBa2I269.jpg'}, {'end': 64.947, 'src': 'embed', 'start': 37.318, 'weight': 1, 'content': [{'end': 40.662, 'text': "So let's go ahead and get started and see what this looks like in Python.", 'start': 37.318, 'duration': 3.344}, {'end': 46.108, 'text': "So, first of all, I've imported the JSON library here at the top of the file, and this is part of the standard library,", 'start': 40.922, 'duration': 5.186}, {'end': 47.59, 'text': "so there's no need to install anything.", 'start': 46.108, 'duration': 1.482}, {'end': 51.394, 'text': 'And I have a multi-line string here that is valid JSON.', 'start': 48.03, 'duration': 3.364}, {'end': 55.518, 'text': 'And you can see that this almost looks like a Python dictionary.', 'start': 52.195, 'duration': 3.323}, {'end': 58.841, 'text': 'So this JSON here has a key called people.', 'start': 55.838, 'duration': 3.003}, {'end': 63.046, 'text': 'And the value of people is an array of more objects.', 'start': 59.362, 'duration': 3.684}, {'end': 64.947, 'text': "So in this case, it's just two more objects.", 'start': 63.086, 'duration': 1.861}], 'summary': 'Using python, imported json library to handle valid json data with an array of objects.', 'duration': 27.629, 'max_score': 37.318, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9N6a-VLBa2I/pics/9N6a-VLBa2I37318.jpg'}], 'start': 0.269, 'title': 'Working with json data in python', 'summary': 'Introduces the basics of working with json data in python, highlighting its common usage in fetching data from online apis and its relevance across various programming languages. it also demonstrates the use of the json library in python and provides an example of valid json data in a python string.', 'chapters': [{'end': 78.439, 'start': 0.269, 'title': 'Working with json data in python', 'summary': 'Introduces the basics of working with json data in python, highlighting its common usage in fetching data from online apis and its relevance across various programming languages. it also demonstrates the use of the json library in python and provides an example of valid json data in a python string.', 'duration': 78.17, 'highlights': ['JSON is a common data format used for storing information and is widely used when fetching data from online APIs.', 'The JSON library is part of the standard library in Python, eliminating the need for additional installation.', 'The provided example demonstrates a valid JSON structure resembling a Python dictionary, with keys and values.']}], 'duration': 78.17, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9N6a-VLBa2I/pics/9N6a-VLBa2I269.jpg', 'highlights': ['JSON is a common data format used for storing information and is widely used when fetching data from online APIs.', 'The JSON library is part of the standard library in Python, eliminating the need for additional installation.', 'The provided example demonstrates a valid JSON structure resembling a Python dictionary, with keys and values.']}, {'end': 405.221, 'segs': [{'end': 105.374, 'src': 'embed', 'start': 78.739, 'weight': 1, 'content': [{'end': 83.063, 'text': "So let's see how to load this into a Python object so that we can work with the data more easily.", 'start': 78.739, 'duration': 4.324}, {'end': 89.248, 'text': 'So to load this into Python from a string, we can use the JSON.loads method.', 'start': 83.423, 'duration': 5.825}, {'end': 95.53, 'text': 'And so to do this, we can say data equals JSON dot load s.', 'start': 89.748, 'duration': 5.782}, {'end': 99.452, 'text': 'And we want to pass in that string into that load s function.', 'start': 95.53, 'duration': 3.922}, {'end': 101.013, 'text': "So I'll save that.", 'start': 99.852, 'duration': 1.161}, {'end': 102.793, 'text': "And now let's print this out.", 'start': 101.453, 'duration': 1.34}, {'end': 105.374, 'text': 'So I will just print out data and run that.', 'start': 102.853, 'duration': 2.521}], 'summary': 'Loading data into python using json.loads method.', 'duration': 26.635, 'max_score': 78.739, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9N6a-VLBa2I/pics/9N6a-VLBa2I78739.jpg'}, {'end': 146.414, 'src': 'embed', 'start': 122.462, 'weight': 0, 'content': [{'end': 132.687, 'text': 'So when we load JSON into a Python object, it uses the following conversion table, let me pull this up here, to convert this into a Python object.', 'start': 122.462, 'duration': 10.225}, {'end': 138.25, 'text': 'So when it parses out that string, if it finds a JSON object, it converts that to a Python dictionary.', 'start': 132.927, 'duration': 5.323}, {'end': 146.414, 'text': 'It converts JSON arrays into a Python list, a string into a Python string, integers into integers,', 'start': 138.65, 'duration': 7.764}], 'summary': 'Loading json into python uses conversion table for parsing data into python objects.', 'duration': 23.952, 'max_score': 122.462, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9N6a-VLBa2I/pics/9N6a-VLBa2I122462.jpg'}, {'end': 301.873, 'src': 'heatmap', 'start': 184.822, 'weight': 4, 'content': [{'end': 192.988, 'text': 'So since our top level key here is an array of values, that should now be equal to a list.', 'start': 184.822, 'duration': 8.166}, {'end': 198.709, 'text': 'So since this is a dictionary, we should be able to access this key of people and that should be a list.', 'start': 193.348, 'duration': 5.361}, {'end': 206.311, 'text': "So let's say let's print out the type and let's access that people key of that dictionary.", 'start': 198.869, 'duration': 7.442}, {'end': 209.692, 'text': 'So if I save that and print that out, then you can see that that is a list.', 'start': 206.511, 'duration': 3.181}, {'end': 210.612, 'text': 'So that got converted.', 'start': 209.712, 'duration': 0.9}, {'end': 216.113, 'text': "So now that we've converted that JSON to Python objects, it's going to be a lot easier to work with these.", 'start': 210.812, 'duration': 5.301}, {'end': 221.174, 'text': 'So now we can loop through all these people and access each one individually.', 'start': 216.433, 'duration': 4.741}, {'end': 229.141, 'text': 'So since that is a list, I could say for person in data and then access that people key there.', 'start': 221.494, 'duration': 7.647}, {'end': 233.644, 'text': 'And then for each one of those, we could just print out the person.', 'start': 229.641, 'duration': 4.003}, {'end': 239.069, 'text': 'So if I save that and run it, then you can see that it ran each of these people individually.', 'start': 233.825, 'duration': 5.244}, {'end': 246.095, 'text': 'And since each of these people in our original JSON are objects themselves, then those should have got converted to dictionaries as well.', 'start': 239.369, 'duration': 6.726}, {'end': 248.898, 'text': 'So now we can access those values within our loop.', 'start': 246.376, 'duration': 2.522}, {'end': 256.644, 'text': 'So if we wanted to access the name of each person, then we can just come here within our loop and say person and then access that name variable.', 'start': 249.178, 'duration': 7.466}, {'end': 262.951, 'text': "So if I save that and run it, then you can see that now we're accessing the names of each person in that JSON file.", 'start': 256.765, 'duration': 6.186}, {'end': 263.851, 'text': 'Okay, great.', 'start': 263.291, 'duration': 0.56}, {'end': 272.814, 'text': "So now that we've seen how to load a JSON string into a Python object, now let's do the reverse of that and dump a Python object into a JSON string.", 'start': 263.931, 'duration': 8.883}, {'end': 276.815, 'text': "And to do this, we'll use the JSON dot dump s method.", 'start': 273.194, 'duration': 3.621}, {'end': 284.359, 'text': "So in our example, let's say that we wanted to remove the phone numbers from each person and then convert this back to a JSON string.", 'start': 277.135, 'duration': 7.224}, {'end': 291.404, 'text': 'So to remove the phone number key and value from each person, within our loop, we can just delete that value.', 'start': 284.779, 'duration': 6.625}, {'end': 298.53, 'text': 'So within our loop here, we can just say del for delete, person, and then access that phone key.', 'start': 291.564, 'duration': 6.966}, {'end': 301.873, 'text': 'And that will delete the key and the value from that dictionary.', 'start': 298.63, 'duration': 3.243}], 'summary': 'Converting json to python objects and accessing data. demonstrating loading and dumping of json strings in python.', 'duration': 37.942, 'max_score': 184.822, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9N6a-VLBa2I/pics/9N6a-VLBa2I184822.jpg'}], 'start': 78.739, 'title': 'Loading and converting json data in python', 'summary': "Covers loading json data into python objects using json.loads method, which converts json objects into python dictionary, json arrays into python list, strings into python string, and integers into integers. it also discusses the conversion of json data to python objects, accessing and manipulating the data, and converting python objects back to json, demonstrating the use of methods like 'dumps', 'del', 'indent', and 'sort_keys'.", 'chapters': [{'end': 146.414, 'start': 78.739, 'title': 'Loading json data into python', 'summary': 'Covers loading json data into a python object using json.loads method, which converts json objects into python dictionary, json arrays into python list, strings into python string, and integers into integers.', 'duration': 67.675, 'highlights': ['When loading JSON data into a Python object, it uses a conversion table to convert JSON objects into a Python dictionary, JSON arrays into a Python list, strings into a Python string, and integers into integers.', 'To load JSON into Python from a string, the JSON.loads method is used, which converts the data into a Python dictionary.', 'The type of the loaded data from JSON into a Python object is a dictionary, which makes it easier to work with the data.']}, {'end': 405.221, 'start': 146.414, 'title': 'Json conversion in python', 'summary': "Covers the conversion of json data to python objects, accessing and manipulating the data, and converting python objects back to json, demonstrating the use of methods like 'dump s', 'del', 'indent', and 'sort keys'.", 'duration': 258.807, 'highlights': ['The chapter covers the conversion of JSON data to Python objects and accessing and manipulating the data.', "Demonstration of converting Python objects back to JSON using methods like 'dump s', 'indent', and 'sort keys'.", "Use of the 'del' method to remove specific keys and values from the Python objects."]}], 'duration': 326.482, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9N6a-VLBa2I/pics/9N6a-VLBa2I78739.jpg', 'highlights': ['When loading JSON data into a Python object, it uses a conversion table to convert JSON objects into a Python dictionary, JSON arrays into a Python list, strings into a Python string, and integers into integers.', 'To load JSON into Python from a string, the JSON.loads method is used, which converts the data into a Python dictionary.', 'The type of the loaded data from JSON into a Python object is a dictionary, which makes it easier to work with the data.', 'The chapter covers the conversion of JSON data to Python objects and accessing and manipulating the data.', "Demonstration of converting Python objects back to JSON using methods like 'dump s', 'indent', and 'sort keys'.", "Use of the 'del' method to remove specific keys and values from the Python objects."]}, {'end': 694.094, 'segs': [{'end': 454.859, 'src': 'heatmap', 'start': 430.822, 'weight': 2, 'content': [{'end': 436.968, 'text': 'And this is a JSON file with a list of all the US states, their abbreviations, and their area codes.', 'start': 430.822, 'duration': 6.146}, {'end': 443.776, 'text': 'So if I wanted to load this file into a Python object, then we can use the JSON load method.', 'start': 437.369, 'duration': 6.407}, {'end': 451.238, 'text': 'So just remember the load method loads a file into a Python object and the load s method we saw before loads a string.', 'start': 444.076, 'duration': 7.162}, {'end': 454.859, 'text': 'So to load in this file, we first have to open it.', 'start': 451.658, 'duration': 3.201}], 'summary': 'Json file contains us states, abbreviations, and area codes; use load method to load into python object.', 'duration': 26.66, 'max_score': 430.822, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9N6a-VLBa2I/pics/9N6a-VLBa2I430822.jpg'}, {'end': 534.147, 'src': 'heatmap', 'start': 472.688, 'weight': 0, 'content': [{'end': 482.313, 'text': 'and now, with this file open, we can load this into a python object by saying data is equal to json.load and load in that file Now.', 'start': 472.688, 'duration': 9.625}, {'end': 489.278, 'text': "if you've never worked with file objects before and you don't really know what's going on here with this with open statement and what we're doing there,", 'start': 482.313, 'duration': 6.965}, {'end': 493.4, 'text': "then I do have a separate video on working with file objects, if you're interested.", 'start': 489.278, 'duration': 4.122}, {'end': 496.022, 'text': "And I'll leave a link to that in the description section below.", 'start': 493.76, 'duration': 2.262}, {'end': 502.646, 'text': "Okay, so now that we've loaded this JSON file into a Python object, we should be able to loop through our data just like we did before.", 'start': 496.322, 'duration': 6.324}, {'end': 507.189, 'text': 'Now, if I look back at the JSON file, we can see that there is a states key here.', 'start': 503.006, 'duration': 4.183}, {'end': 510.79, 'text': 'And then that is a list of objects.', 'start': 507.829, 'duration': 2.961}, {'end': 514.452, 'text': 'And all of these objects have a name, abbreviation, and area code.', 'start': 511.211, 'duration': 3.241}, {'end': 519.414, 'text': 'So if I go back to my list to loop through those, remember that was a states key.', 'start': 514.812, 'duration': 4.602}, {'end': 525.237, 'text': 'So we could say for state in data, then access that states key.', 'start': 519.453, 'duration': 5.784}, {'end': 529.962, 'text': "And then for each of those, let's just print out the entire object.", 'start': 525.997, 'duration': 3.965}, {'end': 534.147, 'text': 'And that object we just called state for the state variable.', 'start': 530.022, 'duration': 4.125}], 'summary': 'Loading json file into python object and looping through data to access states key and print entire objects.', 'duration': 41.764, 'max_score': 472.688, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9N6a-VLBa2I/pics/9N6a-VLBa2I472688.jpg'}, {'end': 586.947, 'src': 'embed', 'start': 558.027, 'weight': 5, 'content': [{'end': 562.67, 'text': 'And you can see that now we have the state and the abbreviation access from that JSON file.', 'start': 558.027, 'duration': 4.643}, {'end': 568.555, 'text': "Okay, so now that we've loaded this JSON from a file, now let's write this Python object out to a JSON file.", 'start': 562.99, 'duration': 5.565}, {'end': 575.241, 'text': "Like we did in the smaller example, let's just remove one of the keys from the data and then write that to a new file.", 'start': 569.116, 'duration': 6.125}, {'end': 578.284, 'text': "So in this example, let's go ahead and just remove the area codes.", 'start': 575.541, 'duration': 2.743}, {'end': 586.947, 'text': 'So like we saw a bit ago, to remove that from a dictionary, we can just say del and then what we want to delete.', 'start': 578.624, 'duration': 8.323}], 'summary': 'Demonstrating json file manipulation in python by removing data and writing to a new file.', 'duration': 28.92, 'max_score': 558.027, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9N6a-VLBa2I/pics/9N6a-VLBa2I558027.jpg'}, {'end': 678.665, 'src': 'heatmap', 'start': 652.966, 'weight': 0.85, 'content': [{'end': 657.711, 'text': 'so in this case we want to dump this to the file we just opened, which is this f variable.', 'start': 652.966, 'duration': 4.745}, {'end': 663.616, 'text': 'so if i save that and run it now, let me open up my sidebar here And here in the same directory,', 'start': 657.711, 'duration': 5.905}, {'end': 666.978, 'text': 'we can see that it created this new underscore states dot JSON.', 'start': 663.616, 'duration': 3.362}, {'end': 670.86, 'text': "So if we open this up, we can see that it's kind of compressed together.", 'start': 667.338, 'duration': 3.522}, {'end': 673.342, 'text': 'But we have states key here.', 'start': 671.22, 'duration': 2.122}, {'end': 678.665, 'text': 'And then within this list, we have name Alabama, abbreviation Alabama.', 'start': 673.462, 'duration': 5.203}], 'summary': "Code successfully dumped data to a file, resulting in a new underscore states dot json file containing compressed data with a 'states' key and list of states with their names and abbreviations.", 'duration': 25.699, 'max_score': 652.966, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9N6a-VLBa2I/pics/9N6a-VLBa2I652966.jpg'}], 'start': 405.521, 'title': 'Working with json in python', 'summary': 'Covers the process of loading, reading, and writing json files in python, demonstrating the use of json load method and loop through the data, accessing specific information, and removing specific keys.', 'chapters': [{'end': 493.4, 'start': 405.521, 'title': 'Loading and writing json files in python', 'summary': 'Covers the process of loading and writing json files in python, demonstrating the use of the json load method to load a file into a python object and explaining the process of opening and reading a json file, using the example of a file containing a list of us states, their abbreviations, and area codes.', 'duration': 87.879, 'highlights': ['The process of loading JSON files into Python objects using the JSON load method is demonstrated, emphasizing the distinction between the load method for files and the loads method for strings.', 'The process of opening and reading a JSON file is explained, utilizing the with statement and demonstrating the use of file objects to load JSON data into a Python object.', 'An example of a JSON file containing a list of US states, their abbreviations, and area codes is presented as a practical illustration of the loading process.']}, {'end': 694.094, 'start': 493.76, 'title': 'Working with json in python', 'summary': 'Explains how to load a json file into a python object, loop through the data, access specific information, and write the python object out to a new json file, removing specific keys and using the json dump method to convert data to a json file.', 'duration': 200.334, 'highlights': ['The chapter explains how to write a Python object out to a JSON file, removing specific keys and using the JSON dump method to convert data to a JSON file.', 'The chapter demonstrates how to load a JSON file into a Python object, loop through the data, and access specific information such as the name and abbreviation.', 'The chapter showcases the process of accessing specific information, such as the name and abbreviation, from the JSON file using the Python object.']}], 'duration': 288.573, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9N6a-VLBa2I/pics/9N6a-VLBa2I405521.jpg', 'highlights': ['The process of loading JSON files into Python objects using the JSON load method is demonstrated, emphasizing the distinction between the load method for files and the loads method for strings.', 'The process of opening and reading a JSON file is explained, utilizing the with statement and demonstrating the use of file objects to load JSON data into a Python object.', 'An example of a JSON file containing a list of US states, their abbreviations, and area codes is presented as a practical illustration of the loading process.', 'The chapter demonstrates how to load a JSON file into a Python object, loop through the data, and access specific information such as the name and abbreviation.', 'The chapter showcases the process of accessing specific information, such as the name and abbreviation, from the JSON file using the Python object.', 'The chapter explains how to write a Python object out to a JSON file, removing specific keys and using the JSON dump method to convert data to a JSON file.']}, {'end': 841.999, 'segs': [{'end': 721.532, 'src': 'embed', 'start': 694.394, 'weight': 3, 'content': [{'end': 698.616, 'text': 'So if I say indent is equal to two and save that and run it.', 'start': 694.394, 'duration': 4.222}, {'end': 704.76, 'text': 'if we open back up our new states JSON file here, then we can see that this is now a lot easier to read.', 'start': 698.616, 'duration': 6.144}, {'end': 711.725, 'text': "Okay so, now that we've seen how to work with JSON strings and files and going back and forth between Python objects,", 'start': 705.22, 'duration': 6.505}, {'end': 717.309, 'text': "now let's look at a real world example of using JSON data so that we can get a sense for how this might be used in practice.", 'start': 711.725, 'duration': 5.584}, {'end': 721.532, 'text': "So it's pretty common for websites to return JSON from their APIs.", 'start': 717.689, 'duration': 3.843}], 'summary': 'Demonstrates working with json in python, including making json data easier to read and using it in a real-world example.', 'duration': 27.138, 'max_score': 694.394, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9N6a-VLBa2I/pics/9N6a-VLBa2I694394.jpg'}, {'end': 796.801, 'src': 'embed', 'start': 729.959, 'weight': 0, 'content': [{'end': 737.425, 'text': 'So I found a Yahoo Finance API that converts United States dollars into other currency.', 'start': 729.959, 'duration': 7.466}, {'end': 744.831, 'text': "So let's see if we can pull down this data, convert the JSON into a Python object, and then parse out some information.", 'start': 737.785, 'duration': 7.046}, {'end': 747.714, 'text': 'So I already have a Python file here to get us started out.', 'start': 745.231, 'duration': 2.483}, {'end': 752.639, 'text': "So to make the request to the Web API, I'm using the built-in urllib module.", 'start': 748.094, 'duration': 4.545}, {'end': 757.784, 'text': "And specifically, I'm importing urlopen from urllib.request.", 'start': 752.959, 'duration': 4.825}, {'end': 762.069, 'text': "Now, you can also use the request library to do this if you're more comfortable using that.", 'start': 758.165, 'duration': 3.904}, {'end': 767.771, 'text': "So you can see that I've already got the URL pasted in here to the URL open function.", 'start': 762.609, 'duration': 5.162}, {'end': 772.672, 'text': 'And then we are setting this source variable here equal to that response.', 'start': 768.291, 'duration': 4.381}, {'end': 775.834, 'text': 'And then we are using the dot read method on that response.', 'start': 772.833, 'duration': 3.001}, {'end': 779.635, 'text': 'Now that will just get the response from the website.', 'start': 776.194, 'duration': 3.441}, {'end': 782.636, 'text': 'And right now this is just going to be a string.', 'start': 780.095, 'duration': 2.541}, {'end': 787.557, 'text': 'So if I run this, then it should just print out all the content of that website.', 'start': 782.836, 'duration': 4.721}, {'end': 789.298, 'text': "You can see it's not very readable.", 'start': 787.617, 'duration': 1.681}, {'end': 791.819, 'text': "We've got new line characters in here and things like that.", 'start': 789.338, 'duration': 2.481}, {'end': 796.801, 'text': "So now let's load this response into a Python object using the JSON module.", 'start': 792.239, 'duration': 4.562}], 'summary': 'Using yahoo finance api to convert usd to other currencies, fetching data, and parsing json in python.', 'duration': 66.842, 'max_score': 729.959, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9N6a-VLBa2I/pics/9N6a-VLBa2I729959.jpg'}], 'start': 694.394, 'title': 'Working with json data in python', 'summary': 'Highlights working with json data in python, including parsing json strings and files, making requests to a public api, converting json into python objects, and cleaning up json data for readability.', 'chapters': [{'end': 841.999, 'start': 694.394, 'title': 'Working with json data in python', 'summary': 'Highlights working with json data in python, including parsing json strings and files, making requests to a public api, converting json into python objects, and cleaning up json data for readability.', 'duration': 147.605, 'highlights': ['Working with JSON strings and files, and going back and forth between Python objects', 'Using a Yahoo Finance API to convert United States dollars into other currency', 'Making a request to the Web API using the built-in urllib module', 'Converting the JSON response into a Python object and cleaning it up for readability using the JSON module']}], 'duration': 147.605, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9N6a-VLBa2I/pics/9N6a-VLBa2I694394.jpg', 'highlights': ['Using a Yahoo Finance API to convert United States dollars into other currency', 'Converting the JSON response into a Python object and cleaning it up for readability using the JSON module', 'Making a request to the Web API using the built-in urllib module', 'Working with JSON strings and files, and going back and forth between Python objects']}, {'end': 1220.724, 'segs': [{'end': 878.28, 'src': 'embed', 'start': 841.999, 'weight': 0, 'content': [{'end': 844.08, 'text': 'so we can see we got some json data.', 'start': 841.999, 'duration': 2.081}, {'end': 851.765, 'text': 'so we can see that the first key is list and then within list we have this meta key which has some metadata.', 'start': 844.08, 'duration': 7.685}, {'end': 856.467, 'text': 'so we can see that it says here that the count is 188 items.', 'start': 851.765, 'duration': 4.702}, {'end': 868.955, 'text': 'and also within this list we have resources and within resources there is another list in here and inside that list we just have the individual resources that have the conversion information.', 'start': 856.467, 'duration': 12.488}, {'end': 872.917, 'text': 'So we have another resource key, then we can see that it has fields.', 'start': 869.015, 'duration': 3.902}, {'end': 878.28, 'text': 'And then this is where we get down to, you know, the name of the conversion and the price for that conversion.', 'start': 873.017, 'duration': 5.263}], 'summary': 'The json data contains 188 items with conversion information and prices.', 'duration': 36.281, 'max_score': 841.999, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9N6a-VLBa2I/pics/9N6a-VLBa2I841999.jpg'}, {'end': 931.129, 'src': 'heatmap', 'start': 899.953, 'weight': 0.714, 'content': [{'end': 904.335, 'text': "So I'm just going to print out the length of that data object.", 'start': 899.953, 'duration': 4.382}, {'end': 907.336, 'text': 'And we are going to access that list.', 'start': 904.535, 'duration': 2.801}, {'end': 911.618, 'text': 'And within that list, we are going to access resources.', 'start': 907.856, 'duration': 3.762}, {'end': 914.599, 'text': "And just so I don't spell this wrong, I'll copy that and paste it in there.", 'start': 911.738, 'duration': 2.861}, {'end': 916.54, 'text': 'So let me save that and run it.', 'start': 914.919, 'duration': 1.621}, {'end': 920.442, 'text': 'And you can see that we did get 188 resources in that list.', 'start': 916.98, 'duration': 3.462}, {'end': 921.283, 'text': 'So that is correct.', 'start': 920.462, 'duration': 0.821}, {'end': 924.305, 'text': "Okay, so now let's actually loop through all of those resources.", 'start': 921.583, 'duration': 2.722}, {'end': 931.129, 'text': "So we can say for item in data, and I should have just copied and pasted that, but that's okay.", 'start': 924.705, 'duration': 6.424}], 'summary': 'Printed length of data object, accessed list with 188 resources, and looped through all resources.', 'duration': 31.176, 'max_score': 899.953, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9N6a-VLBa2I/pics/9N6a-VLBa2I899953.jpg'}, {'end': 1041.161, 'src': 'embed', 'start': 1017.393, 'weight': 3, 'content': [{'end': 1028.425, 'text': 'so if i print out name and price and save that and run it, then now we have the name of each conversion and then the actual price of that conversion.', 'start': 1017.393, 'duration': 11.032}, {'end': 1033.772, 'text': "Okay, so now let's actually use these conversion rates to convert US dollars to a specific currency.", 'start': 1028.744, 'duration': 5.028}, {'end': 1041.161, 'text': "So I'm going to create a new dictionary that has all of these names as the key and all of the conversion rates as the value,", 'start': 1034.133, 'duration': 7.028}], 'summary': 'Using conversion rates to convert us dollars to specific currencies.', 'duration': 23.768, 'max_score': 1017.393, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9N6a-VLBa2I/pics/9N6a-VLBa2I1017393.jpg'}, {'end': 1199.151, 'src': 'embed', 'start': 1165.666, 'weight': 2, 'content': [{'end': 1169.528, 'text': 'and then write a function that accesses this information in a more repeatable way.', 'start': 1165.666, 'duration': 3.862}, {'end': 1179.134, 'text': 'So we can see how understanding how to parse and work with this JSON information can be extremely beneficial for grabbing data from the internet and using it to fit our needs.', 'start': 1169.948, 'duration': 9.186}, {'end': 1181.796, 'text': 'And there are countless other JSON APIs out there,', 'start': 1179.474, 'duration': 2.322}, {'end': 1186.86, 'text': "And it's essential to know how to work with this information if you want to grab data from external sources.", 'start': 1182.196, 'duration': 4.664}, {'end': 1189.583, 'text': 'Okay, so I think that is going to do it for this video.', 'start': 1187.281, 'duration': 2.302}, {'end': 1195.648, 'text': 'Hopefully now you understand how to work with JSON data and convert back and forth between that and Python objects.', 'start': 1189.923, 'duration': 5.725}, {'end': 1199.151, 'text': 'But if anyone does have any questions about what we covered in this video,', 'start': 1196.028, 'duration': 3.123}], 'summary': 'Understanding json parsing is essential for accessing data from external sources.', 'duration': 33.485, 'max_score': 1165.666, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9N6a-VLBa2I/pics/9N6a-VLBa2I1165666.jpg'}], 'start': 841.999, 'title': 'Json data structure and working with json data in python', 'summary': 'Explains the structure of json data, detailing the keys and their respective values, including the count of items and the specific information within the list and resources. it also demonstrates working with json data in python, including accessing and manipulating data, creating dictionaries, and performing currency conversions, with examples showing successful conversion of us dollars to euros and indian rupees.', 'chapters': [{'end': 878.28, 'start': 841.999, 'title': 'Json data structure', 'summary': 'Explains the structure of json data, detailing the keys and their respective values, including the count of items and the specific information within the list and resources.', 'duration': 36.281, 'highlights': ['The count of items in the metadata is 188, indicating the quantity of data available.', 'The structure includes a list with individual resources providing conversion information, including the name and price for each conversion.', "The JSON data contains a 'list' key, a 'meta' key with metadata, and a 'resources' key with individual conversion information."]}, {'end': 1220.724, 'start': 878.521, 'title': 'Working with json data in python', 'summary': 'Demonstrates working with json data in python, including accessing and manipulating data, creating dictionaries, and performing currency conversions, with examples showing successful conversion of us dollars to euros and indian rupees.', 'duration': 342.203, 'highlights': ['The chapter demonstrates working with JSON data in Python, including accessing and manipulating data', 'Creating dictionaries to store conversion rates and performing successful currency conversions', 'Emphasizing the importance of understanding JSON for data retrieval and usage from external sources']}], 'duration': 378.725, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/9N6a-VLBa2I/pics/9N6a-VLBa2I841999.jpg', 'highlights': ['The count of items in the metadata is 188, indicating the quantity of data available.', "The JSON data contains a 'list' key, a 'meta' key with metadata, and a 'resources' key with individual conversion information.", 'The chapter demonstrates working with JSON data in Python, including accessing and manipulating data', 'Creating dictionaries to store conversion rates and performing successful currency conversions', 'Emphasizing the importance of understanding JSON for data retrieval and usage from external sources', 'The structure includes a list with individual resources providing conversion information, including the name and price for each conversion.']}], 'highlights': ['The count of items in the metadata is 188, indicating the quantity of data available.', 'Using a Yahoo Finance API to convert United States dollars into other currency', "The JSON data contains a 'list' key, a 'meta' key with metadata, and a 'resources' key with individual conversion information.", 'The chapter demonstrates working with JSON data in Python, including accessing and manipulating data', 'Creating dictionaries to store conversion rates and performing successful currency conversions', 'Emphasizing the importance of understanding JSON for data retrieval and usage from external sources', 'The process of loading JSON files into Python objects using the JSON load method is demonstrated, emphasizing the distinction between the load method for files and the loads method for strings.', 'The process of opening and reading a JSON file is explained, utilizing the with statement and demonstrating the use of file objects to load JSON data into a Python object.', 'An example of a JSON file containing a list of US states, their abbreviations, and area codes is presented as a practical illustration of the loading process.', 'The chapter demonstrates how to load a JSON file into a Python object, loop through the data, and access specific information such as the name and abbreviation.', 'The chapter showcases the process of accessing specific information, such as the name and abbreviation, from the JSON file using the Python object.', 'The chapter explains how to write a Python object out to a JSON file, removing specific keys and using the JSON dump method to convert data to a JSON file.', 'When loading JSON data into a Python object, it uses a conversion table to convert JSON objects into a Python dictionary, JSON arrays into a Python list, strings into a Python string, and integers into integers.', 'To load JSON into Python from a string, the JSON.loads method is used, which converts the data into a Python dictionary.', 'The type of the loaded data from JSON into a Python object is a dictionary, which makes it easier to work with the data.', 'The chapter covers the conversion of JSON data to Python objects and accessing and manipulating the data.', "Demonstration of converting Python objects back to JSON using methods like 'dump s', 'indent', and 'sort keys'.", "Use of the 'del' method to remove specific keys and values from the Python objects.", 'JSON is a common data format used for storing information and is widely used when fetching data from online APIs.', 'The JSON library is part of the standard library in Python, eliminating the need for additional installation.', 'The provided example demonstrates a valid JSON structure resembling a Python dictionary, with keys and values.']}