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, ∼3966🔥, 0💬
Popular Posts:
Where to find tutorials on JSON (JavaScript Object Notation) text string format? I want to know how ...
How to create a VC# class and build it into a library? If you want to create a VC# class and build i...
How to use the XML to JSON Conversion Tool at freeformatter.com? If you want to try the XML to JSON ...
How To Avoid the Undefined Index Error in PHP? If you don't want your PHP page to give out errors as...
How to create the Hello-3.0.epub package? I have all required files to create Hello-3.0.epub. To cre...