Every line of 'python create json object' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
23 def object_2_json(obj): 24 ''' 25 py字典、数据转成json字符转 26 ''' 27 if obj is None: 28 obj = {} 29 return json.dumps(obj, cls=CJsonEncoder)
25 def python_to_json(python_data): 26 '''Convert python data (tuple, list, dict, etc) into json string''' 27 json_str = json.dumps(python_data, indent=4) 28 return json_str
68 def to_json(jsobj): 69 """Convert a JSON object to a human-readable string.""" 70 return call_json(json.dumps, jsobj)
5 def _custom_json_handler(obj): 6 if isinstance(obj, (datetime.datetime, datetime.time)): 7 return obj.isoformat()
14 def from_json(json_object): 15 if '__class__' in json_object: 16 if json_object['__class__'] == 'time.asctime': 17 return time.strptime(json_object['__value__']) 18 if json_object['__class__'] == 'bytes': 19 return bytes(json_object['__value__']) 20 return json_object