Skip to main content

For serializing Python objects to JSON (dicts) and back

Project description

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.9.0

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

0.8.9

  • Breaking change: Values of primitive types are now cast if possible (e.g. in jsons.load('42', int)).

  • Bugfix: NamedTuples could falsely raise an error when a justified None was provided.

  • Feature: Support for uuid.UUID.

0.8.8

  • Feature: Added the ability to dump recursive objects.

  • Feature: Clearer messaging upon serialization errors.

  • Bugfix: Fix for failing to deserialize UUIDs.

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.

Contributors

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jsons-0.9.0-py3-none-any.whl (43.2 kB view details)

Uploaded Python 3

File details

Details for the file jsons-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: jsons-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 43.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for jsons-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f89935e1064bab4c0c99c5b8d0b02b8632f01bc30ce00f0f58ba6544ba563cae
MD5 06fe8e3fc29ef229b507bfd04c442a70
BLAKE2b-256 b30d67f61df31c71bbadfe7e6818f29e90abfbd941f14a41ff759308da056746

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page