Tools, FAQ, Tutorials:
What Is json.JSONEncoder Class
What Is json.JSONEncoder Class?
✍: FYIcenter.com
json.JSONEncoder class is the underlying class that
supports json.dumps() functions.
The following Python example shows you how to use json.JSONEncoder class to perform the same JSON encoding job as json.dumps function:
>>> import json
>>> l = ['foo', {'bar': ('baz', None, 1.0, {"c": 0, "b": 0, "a": 0})}]
>>> # Encoding with json.dumps() function
>>> j = json.dumps(l, indent=None, separators=(',', ':'), sort_keys=True)
>>> print(j)
["foo",{"bar":["baz",null,1.0,{"a":0,"b":0,"c":0}]}]
>>> # Encoding with json.JSONEncoder class
>>> encoder = json.JSONEncoder(indent=None, separators=(',', ':'),
sort_keys=True)
>>> j = encoder.encode(l)
>>> print(j)
["foo",{"bar":["baz",null,1.0,{"a":0,"b":0,"c":0}]}]
⇒ Extending json.JSONEncoder Class
2018-10-08, ∼2763🔥, 0💬
Popular Posts:
What's Wrong with "while ($c=fgetc($f)) {}" in PHP? If you are using "while ($c=fgetc($f)) {}" to lo...
How to reinstall npm with a node version manager? I am getting permission errors with the current ve...
How to pull NVIDIA CUDA Docker Image with the "docker image pull nvidia/cuda" command? If you are ru...
How To Protect Special Characters in Query String in PHP? If you want to include special characters ...
What validation keywords I can use in JSON Schema to specifically validate JSON Array values? The cu...