Python - dump dict as a json string

i think the problem is json.dump. try

json.dumps(fu)

Use json.dumps to dump a str

>>> import json
>>> json.dumps({'a':'b'})
'{"a": "b"}'

json.dump dumps to a file


You can use json.dumps.

Example:

import json

json.dumps({'zuckerberg':'tech','sachin':'cricket'})

This outputs:

'{"zuckerberg": "tech", "sachin": "cricket"}'

If you want to sort the keys, use sort_keys as the second argument to json.dumps:

json.dumps({'zuckerberg':'tech','sachin':'cricket'},sort_keys=True)

Outputs:

'{"sachin": "cricket", "zuckerberg": "tech"}'

Tags:

Python

Json