用于将python对象序列化为json(dict)并返回
jsons的Python项目详细描述
_ (_) _ ___ ___ _ __ ___ | / __|/ _ \| '_ \/ __| | \__ | (_) | | | \__ \ | |___/\___/|_| |_|___/ _/ | JSON SERIALIZATION |__/ MADE EASY!
~任何python对象到/从json,都很容易!~
| Example of a model to be serialized: ^{pr 2}$Example of the serialization: ^{pr 3}$Output after serialization: ^{pr 4}$ |
安装
pip install jsons
用法
importjsonssome_instance=jsons.load(some_dict,SomeClass)# Deserializationsome_dict=jsons.dump(some_instance)# Serialization
在某些情况下,您有包含其他需要 (反)序列化,例如用列表或指令。你可以使用 typing类,如下所示。
fromtypingimportList,Tupleimportjsons# For more complex deserialization with generic types, use the typing modulelist_of_tuples=jsons.load(some_dict,List[Tuple[AClass,AnotherClass]])
(有关更多示例,请参见 FAQ)
元
最近更新
0.10.1
- 更改:更正类型提示load,loads,loadb。
0.10.0
- 功能:为复数添加了反序列化程序。
0.9.0
- 特性:添加了在加载后立即验证实例的功能。
- 特性:为加载程序函数增强了键入功能。
- 特性:添加了使用多个进程或线程来反序列化列表的功能。
- 功能:添加了jsons.fork()函数。
- 更改:None现在可以加载正确的类型提示,即使是在严格模式下。
- 错误修复:来自JsonSerializable的fork没有复制其设置。
0.8.9
- breaking change:如果可能的话,现在可以转换原语类型的值(例如injsons.load('42', int))。
- 错误修复:当提供对正的None时,namedtuples可能会错误地引发错误。
- 功能:支持uuid.UUID。
0.8.8
- 特性:添加了转储递归对象的功能。
- 功能:序列化错误时更清晰的消息传递。
- 错误修复:修复未能反序列化uuid的问题。