_ (_) _ ___ ___ _ __ ___ | / __|/ _ \| '_ \/ __| | \__ | (_) | | | \__ \ | |___/\___/|_| |_|___/ _/ | JSON SERIALIZATION |__/ MADE EASY!
~ Any Python objects to/from JSON, easily! ~
|
Example of a model to be serialized: @dataclass
class Person:
name: str
birthday: datetime Example of the serialization: jsons.dump(Person('Guido van Rossum', birthday_guido)) Output after serialization: {'birthday': '1956-01-31T12:00:00Z', 'name': 'Guido van Rossum'} |
pip install jsons
import jsons
some_instance = jsons.load(some_dict, SomeClass) # Deserialization
some_dict = jsons.dump(some_instance) # Serialization
In some cases, you have instances that contain other instances that need
(de)serialization, for instance with lists or dicts. You can use the
typing
classes for this as is demonstrated below.
from typing import List, Tuple
import jsons
# For more complex deserialization with generic types, use the typing module
list_of_tuples = jsons.load(some_dict, List[Tuple[AClass, AnotherClass]])
(For more examples, see the FAQ)
- Feature: Added a serializer/deserializer for
time
. - Feature: Added a serializer/deserializer for
timezone
. - Feature: Added a serializer/deserializer for
timedelta
. - Feature: Added a serializer/deserializer for
date
. - Bugfix: Dumping verbose did not store the types of dicts (
Dict[K, V]
). - Bugfix: Loading with
List
(no generic type) failed. - Bugfix: Loading with
Dict
(no generic type) failed. - Bugfix: Loading with
Tuple
(no generic type) failed.
- Bugfix: Loading
Dict[K, V]
did not parseK
.
- Change: Correction of the type hints of
load
,loads
,loadb
.
- Feature: Added a deserializer for complex numbers.
- Feature: Added the ability to validate instances right after loading.
- Feature: Enhanced typing for the loader functions.
- Feature: Added the ability to use multiple processes or threads with deserializing lists.
- Feature: Added the
jsons.fork()
function. - Change:
None
can now be loaded with the right type hints, even in strict-mode. - Bugfix: A fork from
JsonSerializable
did not copy its settings.
Special thanks to the following contributors of code, discussions or suggestions: