Serializing JSON data in Python Last Updated : 02 Jan, 2025 Comments Improve Suggest changes Like Article Like Report Serialization is the process of encoding the from naive data type to JSON format. The Python module json converts a Python dictionary object into JSON object, and list and tuple are converted into JSON array, and int and float converted as JSON number, None converted as JSON null. Let’s take a look at how we serialize Python data to JSON format with these methods: Dump(). Dumps(). json.dump() json.dump() method can be used for writing to JSON file. Write data to a file-like object in json format. Syntax: json.dump(dict, file_pointer) Parameters: dictionary – name of dictionary which should be converted to JSON object. file pointer – pointer of the file opened in write or append mode. Below is the implementation: Converting python object and writing into json file. Python # import module import json # Data to be written data = { "user": { "name": "satyam kumar", "age": 21, "Place": "Patna", "Blood group": "O+" } } # Serializing json and # Writing json file with open( "datafile.json" , "w" ) as write: json.dump( data , write ) Output: data_file.json json.dumps() json.dumps() method can convert a Python object into a JSON string. Syntax: json.dumps(dict) Parameters: dictionary – name of dictionary which should be converted to JSON object. Below is the implementation: Converting python object into json string. Python # import module import json # Data to be written data = { "user": { "name": "satyam kumar", "age": 21, "Place": "Patna", "Blood group": "O+" } } # Serializing json res = json.dumps( data ) print( res ) Output: Comment More infoAdvertise with us Next Article Serializing JSON data in Python kumar_satyam Follow Improve Article Tags : Data Science python Python-json Practice Tags : python Similar Reads Serialize and Deserialize complex JSON in Python JSON stands for JavaScript Object Notation. It is a format that encodes the data in string format. JSON is language-independent and because of that, it is used for storing or transferring data in files. Serialization of JSON object: It means converting a Python object (typically a dictionary) into a 3 min read Read JSON file using Python The full form of JSON is JavaScript Object Notation. It means that a script (executable) file which is made of text in a programming language, is used to store and transfer the data. Python supports JSON through a built-in package called JSON. To use this feature, we import the JSON package in Pytho 4 min read Fetch JSON URL Data and Store in Excel using Python In this article, we will learn how to fetch the JSON data from a URL using Python, parse it, and store it in an Excel file. We will use the Requests library to fetch the JSON data and Pandas to handle the data manipulation and export it to Excel.Fetch JSON data from URL and store it in an Excel file 3 min read Reading and Writing JSON to a File in Python The full form of JSON is Javascript Object Notation. It means that a script (executable) file which is made of text in a programming language, is used to store and transfer the data. Python supports JSON through a built-in package called JSON. To use this feature, we import the JSON package in Pytho 3 min read json.dump() in Python The full-form of JSON is JavaScript Object Notation. It means that a script (executable) file which is made of text in a programming language, is used to store and transfer the data. Python supports JSON through a built-in package called json . To use this feature, we import the json package in Pyth 6 min read json.dumps() in Python JSON is an acronym that stands for JavaScript Object Notation. Despite its name, JSON is a language agnostic format that is most commonly used to transmit data between systems, and on occasion, store data. Programs written in Python, as well as many other programming languages, can ingest JSON forma 6 min read Append to JSON file using Python The full form of JSON is JavaScript Object Notation. It means that a script (executable) file which is made of text in a programming language, is used to store and transfer the data. Python supports JSON through a built-in package called JSON. To use this feature, we import the JSON package in Pytho 2 min read How to Fix - "datetime.datetime not JSON serializable" in Python? In this article, we are going to learn how to fix the error "datetime.datetime not JSON serializable" in Python. datetime.datetime is a class in the Python datetime module that represents a single point in time. This class is not natively supported by the JSON (JavaScript Object Notation) format, wh 4 min read Loop through a JSON array in Python A JSON array is an ordered list of values that can store multiple values such as string, number, boolean, or object. The values in a JSON array must be separated by commas and enclosed in squares in brackets []. In this article, we will learn how we can loop through a JSON array in Python. Iterate o 4 min read Like