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, 1513👍, 0💬
Popular Posts:
Can You Add Values to an Array without Keys in PHP? Can You Add Values to an Array with a Key? The a...
What is json.tool? Can I use it to convert a JSON string a pretty-print format? json.tool is a speci...
Where to find tutorials on how to Read and Write Files in PHP? A collection of tutorials to answer m...
Where to find tutorials on Visual Studio? I want to know How to learn Visual Studio. Here is a large...
How to add a new operation to an API on the Publisher Portal of an Azure API Management Service 2017...