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

0.7.1

  • Bugfix: Deserializing named tuples raised an exception

  • Impl: Restructure of the code (splitted functions, moved to packages, …)

0.7.0

  • Doc: Improved API documentation

  • Feature: Support for loading Union or Optional

  • Feature: Extended strict-mode

  • Feature: Added custom Exceptions

  • Feature: Support for attr-getters

  • Bugfix: Local timezone for datetime serialization improved

0.6.1

  • Feature: Support for loading tuples of variable length

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.2.tar.gz (23.4 kB view hashes)

Uploaded Source

Built Distribution

jsons-0.8.2-py3-none-any.whl (33.3 kB view hashes)

Uploaded Python 3

Supported by

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