Google News
logo
Python Program to Use the separators parameter to change the default separator
In the following example of Python program that uses the `separators` parameter to change the default separators in the `json.dumps()` function :
Program :
import json

# create a dictionary
data = {
    "name": "John",
    "age": 30,
    "city": "New York"
}

# convert the dictionary to a JSON string
json_string = json.dumps(data, indent=4, separators=(". ", " = "))

# print the JSON string
print(json_string)
Output :
{
    "name" = "John". 
    "age" = 30. 
    "city" = "New York"
}
In this example, the `separators` parameter is set to `(". ", " = ")`, which means that a period followed by a space will be used to separate the keys and values, and an equals sign followed by a space will be used to separate the key-value pairs.