{ "info": { "author": "John Millikin", "author_email": "jmillikin@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License (GPL)", "Operating System :: OS Independent", "Programming Language :: C", "Programming Language :: Python", "Programming Language :: Python :: 3", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": ":Author: John Millikin\r\n:Copyright: This document has been placed in the public domain.\r\n\r\nOverview\r\n========\r\n\r\n`JSON `_ is a lightweight data-interchange format. It\r\nis often used for exchanging data between a web server and user agent.\r\n\r\nThis module aims to produce a library for serializing and deserializing\r\nJSON that conforms strictly to RFC 4627.\r\n\r\n.. contents::\r\n\r\nUsage\r\n=====\r\n\r\njsonlib has two functions of interest, ``read`` and ``write``. It also\r\ndefines some exception: ``ReadError``, ``WriteError``, and\r\n``UnknownSerializerError``.\r\n\r\nFor compatibility with the standard library, ``read`` is aliased to\r\n``loads`` and ``write`` is aliased to ``dumps``. They do not have the\r\nsame set of advanced parameters, but may be used interchangeably for\r\nsimple invocations.\r\n\r\nDeserialization\r\n---------------\r\n\r\nTo deserialize a JSON expression, call the ``jsonlib.read`` function with\r\nan instance of ``str`` or ``bytes``. ::\r\n\r\n\t>>> import jsonlib\r\n\t>>> jsonlib.read (b'[\"Hello world!\"]')\r\n\t['Hello world!']\r\n\r\nFloating-point values\r\n~~~~~~~~~~~~~~~~~~~~~\r\n\r\nBy default, ``jsonlib`` will parse values such as \"1.1\" into an instance of\r\n``decimal.Decimal``. To use the built-in value type ``float`` instead, set\r\nthe ``use_float`` parameter to ``True``. ``float`` values are much faster to\r\nconstruct, so this flag may substantially increase parser performance.\r\n\r\nPlease note that using ``float`` will cause a loss of precision when\r\nparsing some values. ::\r\n\r\n\t>>> jsonlib.read ('[3.14159265358979323846]', use_float = True)\r\n\t[3.141592653589793]\r\n\r\nSerialization\r\n-------------\r\n\r\nSerialization has more options, but they are set to reasonable defaults.\r\nThe simplest use is to call ``jsonlib.write`` with a Python value. ::\r\n\r\n\t>>> import jsonlib\r\n\t>>> jsonlib.write (['Hello world!'])\r\n\tb'[\"Hello world!\"]'\r\n\r\nPretty-Printing\r\n~~~~~~~~~~~~~~~\r\n\r\nTo \"pretty-print\" the output, pass a value for the ``indent`` parameter. ::\r\n\r\n\t>>> print (jsonlib.write (['Hello world!'], indent = ' ').decode ('utf8'))\r\n\t[\r\n\t \"Hello world!\"\r\n\t]\r\n\t>>> \r\n\t\r\nMapping Key Sorting\r\n~~~~~~~~~~~~~~~~~~~\r\n\r\nBy default, mapping keys are serialized in whatever order they are\r\nstored by Python. To force a consistent ordering (for example, in doctests)\r\nuse the ``sort_keys`` parameter. ::\r\n\r\n\t>>> jsonlib.write ({'e': 'Hello', 'm': 'World!'})\r\n\tb'{\"m\":\"World!\",\"e\":\"Hello\"}'\r\n\t>>> jsonlib.write ({'e': 'Hello', 'm': 'World!'}, sort_keys = True)\r\n\tb'{\"e\":\"Hello\",\"m\":\"World!\"}'\r\n\r\nEncoding and Unicode\r\n~~~~~~~~~~~~~~~~~~~~\r\n\r\nBy default, the output is encoded in UTF-8. If you require a different\r\nencoding, pass the name of a Python codec as the ``encoding`` parameter. ::\r\n\r\n\t>>> jsonlib.write (['Hello world!'], encoding = 'utf-16-be')\r\n\tb'\\x00[\\x00\"\\x00H\\x00e\\x00l\\x00l\\x00o\\x00 \\x00w\\x00o\\x00r\\x00l\\x00d\\x00!\\x00\"\\x00]'\r\n\r\nTo retrieve an unencoded ``unicode`` instance, pass ``None`` for the\r\nencoding. ::\r\n\r\n\t>>> jsonlib.write (['Hello world!'], encoding = None)\r\n\t'[\"Hello world!\"]'\r\n\r\nBy default, non-ASCII codepoints are forbidden in the output. To include\r\nhigher codepoints in the output, set ``ascii_only`` to ``False``. ::\r\n\r\n\t>>> jsonlib.write (['Hello \\u266a'], encoding = None)\r\n\t'[\"Hello \\\\u266a\"]'\r\n\t>>> jsonlib.write (['Hello \\u266a'], encoding = None, ascii_only = False)\r\n\t'[\"Hello \\u266a\"]'\r\n\r\nMapping Key Coercion\r\n~~~~~~~~~~~~~~~~~~~~\r\n\r\nBecause JSON objects must have string keys, an exception will be raised when\r\nnon-string keys are encountered in a mapping. It can be useful to coerce\r\nmapping keys to strings, so the ``coerce_keys`` parameter is available. ::\r\n\r\n\t>>> jsonlib.write ({True: 1})\r\n\tTraceback (most recent call last):\r\n\tjsonlib.WriteError: Only strings may be used as object keys.\r\n\t>>> jsonlib.write ({True: 1}, coerce_keys = True)\r\n\tb'{\"True\":1}'\r\n\r\nSerializing Other Types\r\n~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\nIf the object implements the iterator or mapping protocol, it will be\r\nhandled automatically. If the object is intended for use as a basic value,\r\nit should subclass one of the supported basic values.\r\n\r\nString-like objects that do not inherit from ``unicode`` or\r\n``UserString.UserString`` will likely be serialized as a list. This will\r\nnot be changed. If iterating them returns an instance of the same type, the\r\nserializer might crash. This (hopefully) will be changed.\r\n\r\nTo serialize a type not known to jsonlib, use the ``on_unknown`` parameter\r\nto ``write``::\r\n\r\n\t>>> from datetime import date\r\n\t>>> def unknown_handler (value, unknown):\r\n\t... if isinstance (value, date):\r\n\t... return str (value)\r\n\t... unknown (value)\r\n\t>>> jsonlib.write ([date (2000, 1, 1)], on_unknown = unknown_handler)\r\n\tb'[\"2000-01-01\"]'\r\n\r\nStreaming Serializer\r\n~~~~~~~~~~~~~~~~~~~~\r\n\r\nWhen serializing large objects, the use of an in-memory buffer may cause\r\ntoo much memory to be used. For these situations, use the ``dump`` function\r\nto write objects to a file-like object::\r\n\r\n\t>>> import sys\r\n\t>>> jsonlib.dump ([\"Written to stdout\"], sys.stdout, encoding = None)\r\n\t[\"Written to stdout\"]\r\n\t>>> with open (\"/dev/null\", \"wb\") as out:\r\n\t... jsonlib.dump ([\"Written to a file\"], out)\r\n\t>>> \r\n\r\nExceptions\r\n-----------\r\n\r\nReadError\r\n~~~~~~~~~\r\n\r\nRaised by ``read`` if an error was encountered parsing the expression. Will\r\ncontain the line, column, and character position of the error.\r\n\r\nNote that this will report the *character*, not the *byte*, of the character\r\nthat caused the error.\r\n\r\nWriteError\r\n~~~~~~~~~~\r\n\r\nRaised by ``write`` or ``dump`` if an error was encountered serializing\r\nthe passed value.\r\n\r\nUnknownSerializerError\r\n~~~~~~~~~~~~~~~~~~~~~~\r\n\r\nA subclass of ``WriteError`` that is raised when a value cannot be\r\nserialized. See the ``on_unknown`` parameter to ``write``.\r\n\r\nChange Log\r\n==========\r\n\r\n1.6.1\r\n-----\r\n* Fixed error in `write()` which could cause output truncation.\r\n\r\n1.6\r\n---\r\n* Faster parsing\r\n\r\n1.5\r\n---\r\n* Faster streaming serialization.\r\n\r\n1.4\r\n---\r\n* Ported to Python 3.\r\n* ``coerce_keys`` no longer attempts to determine the \"JSON\" format for\r\n a coerced value -- it will simply call ``str()``.\r\n* Serializing byte strings is no longer supported -- please use ``str``\r\n objects instead.", "description_content_type": null, "docs_url": null, "download_url": "http://pypi.python.org/pypi/jsonlib-python3/1.6.1", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://launchpad.net/jsonlib", "keywords": "json", "license": "GPL", "maintainer": "", "maintainer_email": "", "name": "jsonlib-python3", "package_url": "https://pypi.org/project/jsonlib-python3/", "platform": "Platform Independent", "project_url": "https://pypi.org/project/jsonlib-python3/", "project_urls": { "Download": "http://pypi.python.org/pypi/jsonlib-python3/1.6.1", "Homepage": "https://launchpad.net/jsonlib" }, "release_url": "https://pypi.org/project/jsonlib-python3/1.6.1/", "requires_dist": null, "requires_python": null, "summary": "JSON serializer/deserializer for Python", "version": "1.6.1" }, "last_serial": 151707, "releases": { "1.4": [ { "comment_text": "", "digests": { "md5": "c748b9b0726b3974e89f9b5e154d4dc8", "sha256": "fd217728c090404f3323f97da53f65314696e825d0e1f1725d89033e8e814b6e" }, "downloads": -1, "filename": "jsonlib-python3-1.4.tar.gz", "has_sig": true, "md5_digest": "c748b9b0726b3974e89f9b5e154d4dc8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 30234, "upload_time": "2009-05-13T05:43:37", "url": "https://files.pythonhosted.org/packages/ff/60/24e6d23b0abe46dccfd1450cacccceb0348fe491d2ed7c99782fd6dc8ca6/jsonlib-python3-1.4.tar.gz" } ], "1.5": [ { "comment_text": "", "digests": { "md5": "2a0dcfd47279544f63e4a171f4c54cb0", "sha256": "57989b6fbb9d7869f97bfa293b31781171159475213502e965d2aeb6ec7f43a9" }, "downloads": -1, "filename": "jsonlib-python3-1.5.tar.gz", "has_sig": true, "md5_digest": "2a0dcfd47279544f63e4a171f4c54cb0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 36630, "upload_time": "2009-12-09T07:37:03", "url": "https://files.pythonhosted.org/packages/ae/30/dab5d57736c5bf4aeac2c5aac257d5d8a806b3ae8cbca04c1020b7c2785e/jsonlib-python3-1.5.tar.gz" } ], "1.6": [], "1.6.1": [ { "comment_text": "", "digests": { "md5": "e16bbafabdbb6500bdca701a0bc6f370", "sha256": "39a3b58d3e4eb3f4172f0e7c6c386c064384a1bd7be9cf41e44fb806835b775c" }, "downloads": -1, "filename": "jsonlib-python3-1.6.1.tar.gz", "has_sig": true, "md5_digest": "e16bbafabdbb6500bdca701a0bc6f370", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 43482, "upload_time": "2010-02-09T17:31:54", "url": "https://files.pythonhosted.org/packages/f2/ec/f632f40dc465923baa25f81f4497e22bf801ba1e485b4ff09055a49c7ed4/jsonlib-python3-1.6.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e16bbafabdbb6500bdca701a0bc6f370", "sha256": "39a3b58d3e4eb3f4172f0e7c6c386c064384a1bd7be9cf41e44fb806835b775c" }, "downloads": -1, "filename": "jsonlib-python3-1.6.1.tar.gz", "has_sig": true, "md5_digest": "e16bbafabdbb6500bdca701a0bc6f370", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 43482, "upload_time": "2010-02-09T17:31:54", "url": "https://files.pythonhosted.org/packages/f2/ec/f632f40dc465923baa25f81f4497e22bf801ba1e485b4ff09055a49c7ed4/jsonlib-python3-1.6.1.tar.gz" } ] }