AnMaree AnMaree - 1 year ago 192
Python Question

What is the difference between json.dumps and json.load?

What is the difference between


From my understanding, one loads JSON into a dictionary and another loads into objects.

Answer Source

dumps takes an object and produces a string:

>>> a = {'foo': 3}
>>> json.dumps(a)
'{"foo": 3}'

load would take a file-like object, read the data from that object, and use that string to create an object:

with open('file.son') as fh:
    a = json.load(fh)

Note that dump and load convert between files and objects, while dumps and loads convert between strings and objects. You can think of the s functions as wrappers around the s-less functions:

def dump(obj, fh):

def load(fh):
    return loads(
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download