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

0.8.2

  • Bugfix: Dumping a namedtuple resulted in a list rather than a dict.

  • Feature: Loading into named tuples can be from lists and dicts.

0.8.1

  • Bugfix: Loading a verbose dump worked only shallow.

0.8.0

  • Feature: Dumping objects can be verbose.

  • Feature: Loading enums without use_enum_name can be with names or values.

  • Bugfix: Loading empty namedtuples caused a problem.

0.7.2

  • Bugfix: Package problem.

Contributors

Special thanks to the following contributors:

Project details


Download files

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

Source Distribution

jsons-0.8.4.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

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

jsons-0.8.4-py3-none-any.whl (33.8 kB view details)

Uploaded Python 3

File details

Details for the file jsons-0.8.4.tar.gz.

File metadata

  • Download URL: jsons-0.8.4.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0

File hashes

Hashes for jsons-0.8.4.tar.gz
Algorithm Hash digest
SHA256 d47cbd3747c36c66960a3447bd972ecb8540bbe20bb786a7957453d1d6ab3c1c
MD5 a8e5baee119362f4970c2522cd6d8622
BLAKE2b-256 3662e269693bac3cb55827a13fe9c8c6acb0977e38015152591035bc70e70b98

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsons-0.8.4-py3-none-any.whl
  • Upload date:
  • Size: 33.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0

File hashes

Hashes for jsons-0.8.4-py3-none-any.whl
Algorithm Hash digest
SHA256 978e783bd51477c1d6f5839defeb2dae3ef24f7b4d3e6616cbcc6cf28765f3b5
MD5 83022215ff9f746c65356bceed5b9dd4
BLAKE2b-256 76f30515a6322b91cc4f99857afcd9d115be0b2b4080b5feb39f55dd35f377b4

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