Tools, FAQ, Tutorials:
Dumping JSON Output to File
How to dump (or encode, serialize) a Python object into file or an output stream as a JSON string using json.dump()?
✍: FYIcenter.com
json.dump(o,fp,...) function performs the same job as json.dumps(o,...)
except that it directs the JSON string to the output stream of a given file pointer.
Here is a Python example that generates a pretty formatted JSON string with property keys sorted:
>>> import json
>>> import sys
>>> l = ['foo', {'bar': ('baz', None, 1.0, {"c": 0, "b": 0, "a": 0})}]
>>> json.dump(l, sys.stdout, indent=3, sort_keys=True)
[
"foo",
{
"bar": [
"baz",
null,
1.0,
{
"a": 0,
"b": 0,
"c": 0
}
]
}
]>>>
⇒ What Is json.JSONEncoder Class
⇐ Generating JSON Strings in Pretty Format
2018-10-08, ∼2064🔥, 0💬
Popular Posts:
What Is Azure API Management Service? Azure API Management as a turnkey solution for publishing APIs...
Where to find tutorials on HTML language? I want to know how to learn HTML. Here is a large collecti...
How to reinstall npm with a node version manager? I am getting permission errors with the current ve...
How to add request query string Parameters to my Azure API operation 2017 version to make it more us...
How to start Docker Daemon, "dockerd", on CentOS systems? If you have installed Docker on your CentO...