_common_impl

This module contains common implementation details of jsons. This module is private, do not import (from) it directly.

Module Contents

Functions

dump_impl(obj, **kwargs)

Serialize the given obj to a JSON equivalent type (e.g. dict, list, int, …).

The way objects are serialized can be finetuned by setting serializer functions for the specific type using set_serializer. :param obj: a Python instance of any sort. :param kwargs: the keyword args are passed on to the serializer function. :return: the serialized obj as a JSON type.

load_impl(json_obj, cls=None, **kwargs)

Deserialize the given json_obj to an object of type cls. If the contents of json_obj do not match the interface of cls, a TypeError is raised.

If json_obj contains a value that belongs to a custom class, there must be a type hint present for that value in cls to let this function know what type it should deserialize that value to.

Example:

class Person:
# No type hint required for name
class Person:

# No type hint required for name

def __init__(self, name):
self.name = name
class Family:

# Person is a custom class, use a type hint

def __init__(self, persons: List[Person]):
self.persons = persons

jsons.load(some_dict, Family)

If no cls is given, a dict is simply returned, but contained values (e.g. serialized datetime values) are still deserialized. :param json_obj: the dict that is to be deserialized. :param cls: a matching class of which an instance should be returned. :param kwargs: the keyword args are passed on to the deserializer function. :return: an instance of cls if given, a dict otherwise.

camelcase(str_)

Return s in camelCase. :param str_: the string that is to be transformed. :return: a string in camelCase.

snakecase(str_)

Return s in snake_case. :param str_: the string that is to be transformed. :return: a string in snake_case.

pascalcase(str_)

Return s in PascalCase. :param str_: the string that is to be transformed. :return: a string in PascalCase.

lispcase(str_)

Return s in lisp-case. :param str_: the string that is to be transformed. :return: a string in lisp-case.