menu
Using json.dumps()
Similar to JavaScript's JSON.stringify(), Python offers json.dumps() to convert a Python object into a JSON string. This is the preferred method for most scenarios as JSON is a widely used and well-structured format.

import json

my_object = {"name": "Alice", "age": 30, "city": "New York"}
json_string = json.dumps(my_object)

print(json_string)  # Output: {"name": "Alice", "age": 30, "city": "New York"}