~ Any Python objects to/from JSON, easily! ~
Jsons is a library that allows you to serialize your plain old Python objects to readable json (dicts or strings) and deserialize them back. No magic, no special types, no polluting your objects. Just you, Python and clean json.
Features¶
- Python 3.5+
- Minimal effort to use!
- No magic, just you, Python and jsons!
- Human readible JSON without pollution!
- Easily customizable and extendable!
- Type hints for the win!
Installing and using¶
Install with pip or conda:
pip install jsons
or
conda install -c conda-forge jsons
And then you’re ready to go:
import jsons
@dataclass
class Car:
color: str
owner: str
dumped = jsons.dump(Car('red', 'Guido'))
The value of dumped
:
{'color': 'red', 'owner': 'Guido'}
And to deserialize, just do:
instance = jsons.load(dumped, Car)
Type hints for the win!
FAQ¶
- Frequently Asked Questions
- Do I need to use dataclasses?
- Do I need to use type hints?
- How can I improve the performance of jsons?
- Is it possible to discard private attributes?
- How can I write a custom serializer?
- How can I write a custom deserializer?
- Why does jsons tolerate additional attributes in my json object compared to the class?
- How can I deserialize without exactly knowing the target class?
- Why not just use
__dict__
? - Why not use the standard
json
library? - Aren’t there already libraries for serialization to json?
- My json contains camelcase, how can I transform to the right case?
- How do the jsons decorators work?
- Can I just participate in discussions on the issues?
- I have an idea for a new feature, what should I do?
- I found a bug, what should I do?
- My question is not listed here!
API¶
- API
- Main functions
- Classes
- Decorators
- Serializers
- Deserializers
- default_datetime_deserializer
- default_list_deserializer
- default_tuple_deserializer
- default_namedtuple_deserializer
- default_union_deserializer
- default_iterable_deserializer
- default_dict_deserializer
- default_mapping_deserializer
- default_enum_deserializer
- default_string_deserializer
- default_nonetype_deserializer
- default_primitive_deserializer
- default_object_deserializer