what does json.dumps do in python? code example
Example 1: python json dump format
>>> import json
>>>
>>> your_json = '["foo", {"bar":["baz", null, 1.0, 2]}]'
>>> parsed = json.loads(your_json)
>>> print(json.dumps(parsed, indent=4, sort_keys=True))
[
"foo",
{
"bar": [
"baz",
null,
1.0,
2
]
}
]
Example 2: python json dump
import json
with open("data_file.json", "w") as write_file:
json.dump(data, write_file)