Open In App

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 Python script. The text in JSON is done through quoted-string which contains the value in key-value mapping within { }. It is similar to the dictionary in Python.

json.dump()

json module in Python module provides a method called dump() which converts the Python objects into appropriate json objects. It is a slight variant of dumps() method.



Difference between dump() and dumps()

dump() dumps()
The dump() method is used when the Python objects have to be stored in a file. The dumps() is used when the objects are required to be in string format and is used for parsing, printing, etc, .
The dump() needs the json file name in which the output has to be stored as an argument. The dumps() does not require any such file name to be passed.
This method writes in the memory and then command for writing to disk is executed separately This method directly writes to the json file
Faster method 2 times slower

dump() and its arguments

Syntax: json.dump(d, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None)

Parameters:




Article Tags :