CaptionsMaker
.com
How To Serialize Python Objects In To JSON Strings?
Edit Subtitles
Download Subtitles
SRT
TXT
Title:
Description:
JSON, Javascript Object Notation is a widely used file format for data exchange all across the web thanks to the prevalence of Javascript frameworks. Converting a Python object into a JSON string is called Serialization. In this video, we will see three different ways of serializing Python objects to JSON. →Timecodes← --------------------- 00:00 Context 00:30 Setup 00:54 The wrong way 01:47 Serializing the Manual Way 02:55 Serializing using an Encoder Function 05:08 Serializing using an Encoder Class 07:08 Closing Remarks →Links← ------------- JSON in Python - Introduction Video - https://www.youtube.com/watch?v=i39oSu-yYXY What is JSON Serialization & Deserialization - https://www.youtube.com/watch?v=ltGzyOADjaE JSON Parsing with Python - https://medium.com/@durgaswaroop/json-parsing-with-python-15a41c6fe03a JSON documentation - https://docs.python.org/3/library/json.html →Social Media← ----------------------- Twitter - https://twitter.com/durgaswaroop Medium - https://medium.com/@durgaswaroop Youtube - https://www.youtube.com/channel/UCQ5HqI-1ewMV1rofUHjiLRA Linkedin - https://www.linkedin.com/in/durgaswaroop/ →Video Summary← --------------------------- We can serialize Python Objects into JSON strings in multiple ways. First approach is to do this manually. We manually pull our the values from the Python object and put it into a JSON string using f-strings. This is the simplest way but it does not offer easy access to change formatting of the output string. The second way is to use an encoder function. An encoder function is one which takes our Python object and returns a JSON encodable object. This object then gets serialized by the "dumps" function. As we are using dumps here, we can customize the indentation and formatting. We pass in the encoder function to the dumps function with the keyword default. The third way is to use an Encoder class. This works similar to an encoder function. We create a class that extends json.JSONEncoder class. In the encoder class we create the default method that has the same content as our encoder function as before. We pass in the class to dumps using the "cls" keyword. We can use the super class (JSONEncoder) to take care of the TypeError for incompatible types. We can also create an object of the encoder class and pass in the object to that object. This way, we can serialize a Python object into a JSON string. →Attributions← ---------------------- (In order) ERF -"Royalty Free Music from Bensound" Melbourne Beach Video - Video by Dan Assis from Pexels - https://www.pexels.com/video/drone-footage-of-brighton-beach-in-melbourne-australia-5042931/ Subscribe Video - Free Stock Video Footage by Videezy →Tools/Gear← --------------------- Operating System - Windows 10 Python IDE - Pycharm Video Editor - Shotcut Audio Editor - Audacity Thumbnail Editor - Canva
YouTube url:
https://www.youtube.com/watch?v=vya47bnrtMo
Created:
15. 10. 2020 15:54:23