Skip to content

JSON dumps Python | Function

  • by

Python JSON dumps() function converts a Python object into a json string. This function is used when the objects are required to be in string format and is used for parsing, printing, etc.

json.dumps(obj, indent=4)

Example JSON dumps Python

Simple example code passing the Python dictionary to json.dumps() function will return a string.

The example converts the input dictionary into a string.

import json

# Dictionary
Dictionary = {1: 'A', 2: 'B', 3: 'C'}

res = json.dumps(Dictionary)
print(res)
print(type(res))

Output:

JSON dumps Python

You can convert Python objects of the following types, into JSON strings:

  • dict
  • list
  • tuple
  • string
  • int
  • float
  • True
  • False
  • None

Do comment if you have any doubts or suggestions on this Python dumps() function.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading