{ "info": { "author": "Franz Steinmetz", "author_email": "franz.steinmetz@dlr.de", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Framework :: Django", "Framework :: Flask", "Intended Audience :: Developers", "Intended Audience :: Information Technology", "Intended Audience :: Science/Research", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", "Topic :: Internet :: WWW/HTTP", "Topic :: Scientific/Engineering :: Interface Engine/Protocol Translator", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Software Development :: Object Brokering", "Topic :: Utilities" ], "description": "The ``jsonconversion`` package\n==============================\n\nThis python module helps converting arbitrary Python objects into JSON strings and back. It extends the basic features\nof the ``JSONEncoder`` and ``JSONDecoder`` classes provided by the native ``json`` package. For this purpose,\n``jsonconversion`` ships with these four classes:\n\nThe ``JSONObject`` class\n------------------------\n\nYour serializable classes should inherit from this class. Hereby, they must implement the methods ``from_dict`` and\n``to_dict``. The example further down describes how to do so.\n\nThe ``JSONExtendedEncoder`` class\n---------------------------------\n\nThis is a class used internally by ``JSONObjectEncoder``. However, it can also be used directly, if you do not need the\nfeatures of ``JSONObjectEncoder`` but want to implement your own encoders.\n\nThe class is especially helpful, if you want custom handling of builtins (``int``, ``dict``, ...) or classes deriving\nfrom builtins. This would not be possible if directly inheriting from ``JSONEncoder``. To do so, override the\n``isinstance`` method and return ``False`` for all types you want to handle in the ``default`` method.\n\nIf you look at the source code of ``JSONObjectEncoder``, you will see how this can be used.\n\nThe ``JSONObjectEncoder`` class\n-------------------------------\n\nEncodes Python objects into JSON strings. Supported objects are:\n\n- Python builtins: ``int``, ``float``, ``str``, ``list``, ``set``, ``dict``, ``tuple``\n- ``type`` objects: ``isinstance(object, type)``\n- All classes deriving from ``JSONObject``\n\nThose objects can of course also be nested!\n\nThe ``JSONObjectDecoder`` class\n-------------------------------\n\nDecodes JSON strings converted using the ``JSONObjectEncoder`` back to Python objects.\n\nThe class adds a custom keyword argument to the ``load[s]`` method: ``substitute_modules``. This parameter takes a\n``dict`` in the form ``{\"old.module.MyClass\": \"new.module.MyClass\"}``. It can be used if you have serialized\n``JSONObject``\\s who's module path has changed.\n\nUsage\n=====\n\nUsing ``jsonconversion`` is easy. You can find further code examples in the ``test`` folder.\n\nEncoding and Decoding\n---------------------\n\nIn order to encode Python objects with JSON conversion and to later decode them, you have to import the Python module\n``json``. The module provides the methods ``dump``/``dumps`` for encoding and ``load``/``loads`` for decoding:\n\n.. code:: python\n\n import json\n\n from jsonconversion.decoder import JSONObjectDecoder\n from jsonconversion.encoder import JSONObjectEncoder\n\n var = (1, 2, 3) # variable to be serialized\n\n # \"dumps\" converts the variable to a string, \"dump\" directly writes it to a file\n str_var = json.dumps(var, cls=JSONObjectEncoder)\n # Equivalently, \"loads\" converts the object back from a string. \"load\" from a file\n var_2 = json.loads(str_var, cls=JSONObjectDecoder)\n assert var == var_2\n\nDeriving from JSONObject\n------------------------\n\nIn order to serialize arbitrary, self-written classes, they must derive from ``JSONObject`` and implement the two\nmethods ``from_dict`` and ``to_dict``:\n\n.. code:: python\n\n class MyClass(JSONObject):\n\n def __init__(self, a, b, c):\n self.a = a\n self.b = b\n self.c = c\n\n @classmethod\n def from_dict(cls, dict_):\n return cls(dict_['a'], dict_['b'], dict_['c'])\n\n def to_dict(self):\n return {'a': self.a, 'b': self.b, 'c': self.c}\n\n def __eq__(self, other):\n return self.a == other.a and self.b == other.b and self.c == other.c\n\nGeneral notes\n-------------\n\n- ``jsonconversion`` stores the class path in the JSON string when serializing a JSONObject. When decoding the object\n back, it automatically imports the correct module. You only have to ensure that the module is within your\n ``PYTHONPATH``.\n\n- The ``to_dict`` and ``from_dict`` methods only need to specify the elements of a class, needed to recreate the\n object. Derived attributes of a class (like ``age`` from ``year_born``) do not need to be serialized.\n\n- If you compare the original object with the object obtained from serialization and deserialization using ``is``, they\n will differ, as these are objects at different locations in memory. Also a comparison of JSONObject with ``==`` will\n fail, if you do not tell Python how to compare two objects. This is why ``MyClass`` overrides the ``__eq__`` method.", "description_content_type": "", "docs_url": null, "download_url": "https://github.com/DLR-RM/python-jsonconversion/tarball/master", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/DLR-RM/python-jsonconversion", "keywords": "json,conversion,serialization", "license": "BSD", "maintainer": "Franz Steinmetz", "maintainer_email": "franz.steinmetz@dlr.de", "name": "jsonconversion", "package_url": "https://pypi.org/project/jsonconversion/", "platform": "", "project_url": "https://pypi.org/project/jsonconversion/", "project_urls": { "Download": "https://github.com/DLR-RM/python-jsonconversion/tarball/master", "Homepage": "https://github.com/DLR-RM/python-jsonconversion" }, "release_url": "https://pypi.org/project/jsonconversion/0.2.12/", "requires_dist": null, "requires_python": ">=2.6", "summary": "This python module helps converting arbitrary Python objects into JSON strings and back.", "version": "0.2.12" }, "last_serial": 5441007, "releases": { "0.2.10": [ { "comment_text": "", "digests": { "md5": "66314629c8e785eefafaf87f81966179", "sha256": "d93706811519f5f11defe17cba3a8eff760a37285052eefe9f85b68a15f44b38" }, "downloads": -1, "filename": "jsonconversion-0.2.10.tar.gz", "has_sig": false, "md5_digest": "66314629c8e785eefafaf87f81966179", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.6", "size": 11334, "upload_time": "2019-03-11T08:43:59", "url": "https://files.pythonhosted.org/packages/29/38/448fd3cbda3e78a7bd62b511c99a895a2af4ec31dc08e757c52a1f70cee6/jsonconversion-0.2.10.tar.gz" } ], "0.2.11": [ { "comment_text": "", "digests": { "md5": "791bb885a9a515ca8b8bcc099dc9ac97", "sha256": "80fa382ced3550cb4129590773931a10ef5ccef23f414864dfa08995b3001f6e" }, "downloads": -1, "filename": "jsonconversion-0.2.11.tar.gz", "has_sig": false, "md5_digest": "791bb885a9a515ca8b8bcc099dc9ac97", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.6", "size": 12910, "upload_time": "2019-06-18T11:26:30", "url": "https://files.pythonhosted.org/packages/54/4e/8022250471d342fe52b2397b9bb976ed79dd357c2d0f0844680783b171c8/jsonconversion-0.2.11.tar.gz" } ], "0.2.12": [ { "comment_text": "", "digests": { "md5": "00d0856388338a1167ef598d7f48514f", "sha256": "b4355a311475f85ee899776737344cc3106a437b4f4ed6179650323bd713883e" }, "downloads": -1, "filename": "jsonconversion-0.2.12.tar.gz", "has_sig": false, "md5_digest": "00d0856388338a1167ef598d7f48514f", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.6", "size": 13509, "upload_time": "2019-06-24T14:55:38", "url": "https://files.pythonhosted.org/packages/85/1a/dd7e0218cf4e6922201449bb64679d409b43f1e4907877dd4844ac15e437/jsonconversion-0.2.12.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "a8023fbad58e4832926ea03be6f26f72", "sha256": "ba1ff2f1c1f966912628e0260e69ac4b471179f9ba5aff3097bff13c619542f4" }, "downloads": -1, "filename": "jsonconversion-0.2.2.tar.gz", "has_sig": false, "md5_digest": "a8023fbad58e4832926ea03be6f26f72", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10912, "upload_time": "2017-04-04T05:59:29", "url": "https://files.pythonhosted.org/packages/18/eb/50d6172c996fbc0fe805ad518e70f130cdd0b1f9dc4fdf245dab2725e178/jsonconversion-0.2.2.tar.gz" } ], "0.2.3": [ { "comment_text": "", "digests": { "md5": "4abf79fb0c2c2d96041c006366efb86a", "sha256": "4f561dfd2cd7b90c08ce1aae5451093d5b23641d1df39ac22a211272afe5cb04" }, "downloads": -1, "filename": "jsonconversion-0.2.3.tar.gz", "has_sig": false, "md5_digest": "4abf79fb0c2c2d96041c006366efb86a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11498, "upload_time": "2017-04-10T13:20:53", "url": "https://files.pythonhosted.org/packages/ab/e9/1ca38f55e95b8e6c7d0b1c89c8a0265f9c6851389ca845eb38c0bd064789/jsonconversion-0.2.3.tar.gz" } ], "0.2.4": [ { "comment_text": "", "digests": { "md5": "a92fed0c92fa90e70dd552977acfb68c", "sha256": "154140335dbf43f77df7bf615d2d521b3d9ee1bcba5ff1ebb2c9643fa1e065fa" }, "downloads": -1, "filename": "jsonconversion-0.2.4.tar.gz", "has_sig": false, "md5_digest": "a92fed0c92fa90e70dd552977acfb68c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11000, "upload_time": "2017-04-10T13:37:36", "url": "https://files.pythonhosted.org/packages/3b/6a/bb259c113731bbeda7c8f0b061d1819795595b43064be32b275742b010a3/jsonconversion-0.2.4.tar.gz" } ], "0.2.5": [ { "comment_text": "", "digests": { "md5": "7cc83276b40941719a5e350aec8bcec3", "sha256": "644c5e76c33ccfb2d298d14867c14245561a6e4248852e7c340cce2ad0e10e5e" }, "downloads": -1, "filename": "jsonconversion-0.2.5.tar.gz", "has_sig": false, "md5_digest": "7cc83276b40941719a5e350aec8bcec3", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.6, !=3.*", "size": 11387, "upload_time": "2017-09-27T12:13:27", "url": "https://files.pythonhosted.org/packages/d0/95/e8cc8cd3d5da23a722563da248c2e913dcb379cf2c221ff431b36c8b6af5/jsonconversion-0.2.5.tar.gz" } ], "0.2.6": [ { "comment_text": "", "digests": { "md5": "9bec3505d514c2a86dbf4d6946cdb1a0", "sha256": "a17919bce0ddc105e8ef67755b1f4c5443ea666637e56eed1bdbb06dbc66f8eb" }, "downloads": -1, "filename": "jsonconversion-0.2.6-py2.py3.tar.gz", "has_sig": false, "md5_digest": "9bec3505d514c2a86dbf4d6946cdb1a0", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.6", "size": 11177, "upload_time": "2018-09-28T08:47:15", "url": "https://files.pythonhosted.org/packages/e5/43/e9fe0c569ad6b64e8d4b353388a5544cdb54d5ac6c3e7cad72575c5677cc/jsonconversion-0.2.6-py2.py3.tar.gz" } ], "0.2.7": [ { "comment_text": "", "digests": { "md5": "1d5f02127ccb4d896a0cf00285707e32", "sha256": "d1608b59b00d6a048235fd0d14ee483bb9e69c38cff7e9195d5ef4f26dc2ba64" }, "downloads": -1, "filename": "jsonconversion-0.2.7.tar.gz", "has_sig": false, "md5_digest": "1d5f02127ccb4d896a0cf00285707e32", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.6", "size": 11185, "upload_time": "2018-09-28T08:52:18", "url": "https://files.pythonhosted.org/packages/57/53/35ebeb28d4758c8c2f57d0faac2a0e065f840794987b8588df65ba836bad/jsonconversion-0.2.7.tar.gz" } ], "0.2.8": [ { "comment_text": "", "digests": { "md5": "ec8ca6ebe01a18578d90f249a0fb4859", "sha256": "833305a252a000641aedeb8748a86cb88a5b19827d6f580bba274b16ac8ac233" }, "downloads": -1, "filename": "jsonconversion-0.2.8.tar.gz", "has_sig": false, "md5_digest": "ec8ca6ebe01a18578d90f249a0fb4859", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.6", "size": 11276, "upload_time": "2018-11-27T12:15:48", "url": "https://files.pythonhosted.org/packages/df/bc/d3de3f5cc28eb62791c2c22daf689c8bba16e12d0ea86099f0707e0be1b2/jsonconversion-0.2.8.tar.gz" } ], "0.2.9": [ { "comment_text": "", "digests": { "md5": "97ae1c0db3cec0f1963e1b962034e08f", "sha256": "f0225980678c91c67c5beeec0c95696d9b4a12b8bcc1c98e6d17a5c6a49bb6a7" }, "downloads": -1, "filename": "jsonconversion-0.2.9.tar.gz", "has_sig": false, "md5_digest": "97ae1c0db3cec0f1963e1b962034e08f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11316, "upload_time": "2018-12-10T08:35:37", "url": "https://files.pythonhosted.org/packages/d0/1a/073693fb8f62c1027e806c055ab272f2026acf83271398f78c7da4e56eba/jsonconversion-0.2.9.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "00d0856388338a1167ef598d7f48514f", "sha256": "b4355a311475f85ee899776737344cc3106a437b4f4ed6179650323bd713883e" }, "downloads": -1, "filename": "jsonconversion-0.2.12.tar.gz", "has_sig": false, "md5_digest": "00d0856388338a1167ef598d7f48514f", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.6", "size": 13509, "upload_time": "2019-06-24T14:55:38", "url": "https://files.pythonhosted.org/packages/85/1a/dd7e0218cf4e6922201449bb64679d409b43f1e4907877dd4844ac15e437/jsonconversion-0.2.12.tar.gz" } ] }