A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/data-science/serializing-json-data-in-python/ below:

Serializing JSON data in Python

Serializing JSON data in Python

Last Updated : 23 Jul, 2025

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:

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:

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:

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:



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4