ahmetkucuk / jsons

A Python lib for (de)serializing Python objects to/from JSON

Home Page:https://jsons.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PyPI version Documentation Status Build Status Code Coverage Scrutinizer Code Quality Downloads Maintainability

   _
  (_)
   _ ___  ___  _ __  ___
  | / __|/ _ \| '_ \/ __|
  | \__ | (_) | | | \__ \
  | |___/\___/|_| |_|___/
 _/ | JSON SERIALIZATION
|__/      MADE EASY!

~ Any Python objects to/from JSON, easily! ~

  • 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!

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'}

Installation

pip install jsons

Usage

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)

Documentation

Meta

Recent updates

0.8.7

  • Breaking change: The default serializers and deserializers now use keyword-only arguments.
  • Feature: Added strip_attr argument for omitting specific attributes when serializing objects.
  • Feature: The private attributes from ABC are now excluded from a dump.

0.8.6

  • Feature: Support for typing.NewType.
  • Bugfix: Deserializing a Dict[K, V] failed in 3.7.

0.8.5

  • Feature: Support for Deque.
  • Feature: Support for Counter.
  • Feature: Support for OrderedDict.
  • Feature: Support for Defaultdict.
  • Feature: Support for ChainMap.

0.8.4

  • Feature: Support for textual type hints.
  • Feature: Automatically announce classes when dumped.
  • Bugfix: Support for from __future__ import annotations

0.8.3

  • Bugfix: Loading verbose dumped objects could fail if lists where involved.

Contributors

Special thanks to the following contributors of code, discussions or suggestions:

About

A Python lib for (de)serializing Python objects to/from JSON

https://jsons.readthedocs.io

License:MIT License


Languages

Language:Python 100.0%