From: https://mp.weixin.qq.com/s/04y0mj_oTc6DmEf_bcbBCg
---------------------------------------------------------------------------------------
# should install orjson before running it
import orjson
def test_orjson():
# JSON编码
data = {
"name": "Kimi",
"age": 30,
"is_member": True,
"skills": ["Python", "Data Analysis", "Machine Learning"]
}
json_bytes = orjson.dumps(data)
print(json_bytes)
print("---分隔符1---")
# JSON解码
decoded_data = orjson.loads(json_bytes)
print(decoded_data)
print("---分隔符2---")
# 3.高级用法:orjson提供了一些高级功能,比如自定义选项来优化性能。
# 使用自定义选项进行编码
options = orjson.OPT_INDENT_2 | orjson.OPT_NON_STR_KEYS
json_pretty = orjson.dumps(data, option=options)
print(json_pretty)