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, ∼1956🔥, 0💬
Popular Posts:
How to add an API to an API product for internal testing on the Publisher Portal of an Azure API Man...
Can Multiple Paragraphs Be Included in a List Item? Yes. You can include multiple paragraphs in a si...
Where to find tutorials on Python programming language? I want to learn Python. Here is a large coll...
What's Wrong with "while ($c=fgetc($f)) {}" in PHP? If you are using "while ($c=fgetc($f)) {}" to lo...
What is EPUB 2.0 Metadata "dc:creator" and "dc:contributor" elements? EPUB 2.0 Metadata "dc:creator"...