Skip to main content

Improved JSON deserialization for Python

Project description

j_classify

Improved JSON deserializer for Python that allows for remapping to custom object types and nested objects. This allows for saving/loading complex Python objects, like using pickle while still preserving them in a human-readable format.

Example Usage:

import json

import j_classify


class test_class_1(j_classify.j_object):
    def __init__(self) -> None:
        super().__init__()
        self.name = "test_class_1"
        self.number = 1
        self.boolean = True
        self.children: list = []


class test_class_2(j_classify.j_object):
    def __init__(self) -> None:
        super().__init__()
        self.name = "test_class_2"
        self.number = 2
        self.boolean = False
        self.children: list = []


class test_class_3(j_classify.j_object):
    def __init__(self) -> None:
        super().__init__()
        self.name = "test_class_3"
        self.number = 3
        self.boolean = True


if __name__ == "__main__":
    obj_1 = test_class_1()
    obj_1.name = "obj_1"
    obj_1.number = 2
    obj_1.boolean = False

    obj_2 = test_class_2()
    obj_2.name = "obj_2"
    obj_2.number = 3
    obj_2.boolean = True
    obj_1.children.append(obj_2)

    obj_3 = test_class_3()
    obj_3.name = "obj_3"
    obj_3.number = 4
    obj_3.boolean = False
    obj_2.children.append(obj_3)

    # Dump the object to JSON - use the j_object_encoder class for the cls argument
    obj_data = json.dumps(obj_1, cls=j_classify.j_object_encoder, indent=4)

    # Load the object from JSON - use the load_j_object function for the object_hook
    loaded_obj_1 = json.loads(obj_data, object_hook=j_classify.load_j_object)

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

j_classify-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

j_classify-0.1.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file j_classify-0.1.0.tar.gz.

File metadata

  • Download URL: j_classify-0.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.7

File hashes

Hashes for j_classify-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e2666cb9e050fd187cc253eb288b19e5b47d939c487126962a8789f5d7aed1ef
MD5 049ef692eca071c330511f58e28d0ed5
BLAKE2b-256 77d7ff873453946f3e023e2a0e54da8f7d07fe7e3d5b665c6562e1e54512ebe9

See more details on using hashes here.

File details

Details for the file j_classify-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: j_classify-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.7

File hashes

Hashes for j_classify-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b776c7d79f15ffe84800aa8ebb3a66f832a2d21e4735af8a8a8dc2b686927ac5
MD5 af8ccb9643a163bf907fd7585549e7e8
BLAKE2b-256 2ea7ff750bcb6a6a464e001ea45486540e94f6f9a17efa41c67e2f9854fd0119

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