{ "info": { "author": "Alec Flett", "author_email": "alecf@flett.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": ":Author: John Millikin\n:Copyright: This document has been placed in the public domain.\n\nOverview\n========\n\nThis is yet another library for reading/writing json. The goal is to\nbe API compatible with `simplejson\n`_, except that it is written\npurely in C and is thus 5x-20x faster for both encoding and decoding,\ndepending on the data.\n\nThis is a fork of the `jsonlib `_\nproject by the folks over at `Freebase `_ who\nhave data coming from a variety of internal sources in different\nencodings and formats, not all of which could simply be represented by\nstrict JSON.\n\nThus, the intent of this fork is to be more lenient in its\nencoding and decoding (as simplejson is) allowing things like\nNaN/-NaN/Infinity, automatic handling of unicode, and more. The first\nrelease of jsonlib2 was version 1.4, which was forked from jsonlib\n1.3.10.\n\n.. contents::\n\nUsage\n=====\n\njsonlib2 has two functions of interest, ``read`` and ``write``. It also\ndefines some exception: ``ReadError``, ``WriteError``, and\n``UnknownSerializerError``.\n\nFor compatibility with the standard library, ``read`` is aliased to\n``loads`` and ``write`` is aliased to ``dumps``. They do not have the\nsame set of advanced parameters, but may be used interchangeably for\nsimple invocations.\n\nDeserialization\n---------------\n\nTo deserialize a JSON expression, call the ``jsonlib2.read`` function with\nan instance of ``str`` or ``unicode``. ::\n\n\t>>> import jsonlib2\n\t>>> jsonlib2.read ('[\"Hello world!\"]')\n\t[u'Hello world!']\n\nFloating-point values\n~~~~~~~~~~~~~~~~~~~~~\n\nBy default, ``jsonlib2`` will parse values such as \"1.1\" into an instance of\n``decimal.Decimal``. To use the built-in value type ``float`` instead, set\nthe ``use_float`` parameter to ``True``. Please note that this may cause a\nloss of precision when parsing some values. ::\n\n\t>>> jsonlib2.read ('[1.5]', use_float = True)\n\t[1.5]\n\t>>> jsonlib2.read ('[1.1]', use_float = True)\n\t[1.1000000000000001]\n\t>>> jsonlib2.read ('[3.14159265358979323846]', use_float = True)\n\t[3.1415926535897931]\n\nSerialization\n-------------\n\nSerialization has more options, but they are set to reasonable defaults.\nThe simplest use is to call ``jsonlib2.write`` with a Python value. ::\n\n\t>>> import jsonlib2\n\t>>> jsonlib2.write (['Hello world!'])\n\t'[\"Hello world!\"]'\n\nPretty-Printing\n~~~~~~~~~~~~~~~\n\nTo \"pretty-print\" the output, pass a value for the ``indent`` parameter. ::\n\n\t>>> print jsonlib2.write (['Hello world!'], indent = ' ')\n\t[\n\t \"Hello world!\"\n\t]\n\t>>> \n\t\nMapping Key Sorting\n~~~~~~~~~~~~~~~~~~~\n\nBy default, mapping keys are serialized in whatever order they are\nstored by Python. To force a consistent ordering (for example, in doctests)\nuse the ``sort_keys`` parameter. ::\n\n\t>>> jsonlib2.write ({'e': 'Hello', 'm': 'World!'})\n\t'{\"m\":\"World!\",\"e\":\"Hello\"}'\n\t>>> jsonlib2.write ({'e': 'Hello', 'm': 'World!'}, sort_keys = True)\n\t'{\"e\":\"Hello\",\"m\":\"World!\"}'\n\nEncoding and Unicode\n~~~~~~~~~~~~~~~~~~~~\n\nBy default, the output is encoded in UTF-8. If you require a different\nencoding, pass the name of a Python codec as the ``encoding`` parameter. ::\n\n\t>>> jsonlib2.write (['Hello world!'], encoding = 'utf-16-be')\n\t'\\x00[\\x00\"\\x00H\\x00e\\x00l\\x00l\\x00o\\x00 \\x00w\\x00o\\x00r\\x00l\\x00d\\x00!\\x00\"\\x00]'\n\nTo retrieve an unencoded ``unicode`` instance, pass ``None`` for the\nencoding. ::\n\n\t>>> jsonlib2.write (['Hello world!'], encoding = None)\n\tu'[\"Hello world!\"]'\n\nBy default, non-ASCII codepoints are forbidden in the output. To include\nhigher codepoints in the output, set ``ensure_ascii`` to ``False``. ::\n\n\t>>> jsonlib2.write ([u'Hello \\u266a'], encoding = None)\n\tu'[\"Hello \\\\u266a\"]'\n\t>>> jsonlib2.write ([u'Hello \\u266a'], encoding = None, ensure_ascii = False)\n\tu'[\"Hello \\u266a\"]'\n\nMapping Key Coercion\n~~~~~~~~~~~~~~~~~~~~\n\nBecause JSON objects must have string keys, strings will be 'coerced'\nto strings. You can override this with the ``coerce_keys`` parameter,\nwhcih will raise exception when non-string keys are encountered in a\nmapping. ::\n\n\t>>> jsonlib2.write ({True: 1})\n\t'{\"true\":1}'\n\t>>> jsonlib2.write ({True: 1}, coerce_keys = False)\n\tTraceback (most recent call last):\n\tWriteError: Only strings may be used as object keys.\n\nSerializing Other Types\n~~~~~~~~~~~~~~~~~~~~~~~\n\nIf the object implements the iterator or mapping protocol, it will be\nhandled automatically. If the object is intended for use as a basic value,\nit should subclass one of the supported basic values.\n\nString-like objects that do not inherit from ``str``, ``unicode``, or\n``UserString.UserString`` will likely be serialized as a list. This will\nnot be changed. If iterating them returns an instance of the same type, the\nserializer might crash. This (hopefully) will be changed.\n\nTo serialize a type not known to jsonlib2, use the ``default`` parameter\nto ``write``::\n\n\t>>> from datetime import date\n\t>>> def default_handler (value):\n\t... if isinstance (value, date): return str (value)\n\t... raise jsonlib2.UnknownSerializerError\n\t>>> jsonlib2.write ([date (2000, 1, 1)], default = default_handler)\n\t'[\"2000-01-01\"]'\n\nStreaming Serializer\n~~~~~~~~~~~~~~~~~~~~\n\nWhen serializing large objects, the use of an in-memory buffer may cause\ntoo much memory to be used. For these situations, use the ``dump`` function\nto write objects to a file-like object::\n\n\t>>> import sys\n\t>>> jsonlib2.dump ([\"Written to stdout\"], sys.stdout)\n\t[\"Written to stdout\"]\n\t>>> \n\nExceptions\n-----------\n\nReadError\n~~~~~~~~~\n\nRaised by ``read`` if an error was encountered parsing the expression. Will\ncontain the line, column, and character position of the error.\n\nNote that this will report the *character*, not the *byte*, of the character\nthat caused the error.\n\nWriteError\n~~~~~~~~~~\n\nRaised by ``write`` or ``dump`` if an error was encountered serializing\nthe passed value.\n\nUnknownSerializerError\n~~~~~~~~~~~~~~~~~~~~~~\n\nA subclass of ``WriteError`` that is raised when a value cannot be\nserialized. See the ``default`` parameter to ``write``.\n\nChange Log\n==========\n\n1.5.1\n-----\n* Fixed problem compiling on Python before version 2.6, as reported by \n Carlo Barrettara and others\n\n1.5\n---\n* Major API change - add lots of support for simplejson keywords\n* dropped use of Decimal module, and thus the ``use_float`` parameter\n in ``load``. In ``dump``, use ``default``.\n* in ``load``, added parsing support for Infinity, -Infinity, NaN\n* in ``load``, added support for ``parse_float``, ``parse_int``,\n ``parse_constant``\n* in ``dump``, ``allow_non_numbers`` became ``allow_nan``\n* in ``dump``, ``allow_nan`` (formerly ``allow_non_numbers``) is now\n True by default\n* in ``dump``, ``on_unknown`` became ``default``\n* in ``dump``, ``ascii_only`` became ``ensure_ascii``\n* in ``dump``, ``coerce_keys`` is now True by default\n* Removed JSON-strict restriction, allowing both ``load`` and ``dump``\n to deal with objects that are not lists or dictionaries at the root\n level.\n\n1.4.2\n-----\n* Memory leak fix\n\n1.4.1\n-----\n* Added ``escape_slash`` parameter to ``write()`` to stop escaping the\n '/' character\n\n1.4\n---\n* First release as jsonlib2\n\n1.3.10\n------\n* Implemented the ``use_float`` parameter to ``read()``.\n\n1.3.9\n-----\n* Fixed a crash on some platforms when passing a non-string object for\n indentation.\n\n1.3.8\n-----\n* Fixed memory leak when auto-decoding bytestrings.\n* Fixed potential memory leak when using ``on_unknown`` handlers that\n return invalid objects.\n\n1.3.7\n-----\n* Fixed error reporting positions of syntax errors that occur immediately\n after a newline.\n* Add ``loads()`` and ``dumps()`` as aliases to ``read()`` and ``write()``,\n respectively, for compatibility with the new ``json`` standard library\n module.\n* Small fixes to the test suite to clear spurious errors caused by\n differences between the behavior of ``repr()`` on instances of\n ``decimal.Decimal`` and ``UnicodeDecodeError``.\n\n1.3.6\n-----\n* If an unterminated object or array is encountered, report its start\n location properly.\n* Improved reporting of unknown escape codes.\n* Raise an exception when parsing a root value that is not an array\n or object.\n* Allow instances of ``UserString`` to be used as object keys.\n* Implemented the ``dump()`` function.\n\n1.3.5\n-----\n* Bugfix release, corrects serialization of ``dict`` when ``PyDict_Next()``\n skips indexes.\n\n1.3.4\n-----\n* Fixes an issue with reporting the column of a syntax error when the\n error is followed by a newline.\n* Removed remaining Python wrapper for ``read``.\n\n1.3.3\n-----\n* Support the ``on_unknown`` parameter to ``write``.\n* Corrected typo in invalid whitespace detection.\n* Added ``__version__`` attribute.\n* Merged all code into ``jsonlib2`` and ``_jsonlib`` modules, instead of\n a package.\n\n1.3.2\n-----\n* Improved the README.\n* Support for reading text encoded with the ``utf-8-sig`` codec.\n* Use ``codecs`` module for detecting BOMs in input data.\n* Forbid non-whitespace strings from being used for indentation.\n\n1.3.1\n-----\n* Removed the Python implementations of the serializer and deserializer.\n* Detect and raise an exception if invalid surrogate pairs are serialized\n or deserialized.\n* Detect and raise an exception if reserved codepoints are serialized or\n deserialized.\n* Added support for operating in a process with multiple Python interpreters.\n* Performance improvements.\n\n1.3.0\n-----\n* Allow ``python setup.py test`` to work.\n* Added ``encoding`` parameter to ``write``, which controls the output\n encoding. The default encoding is ``utf-8``. If the encoding is ``None``,\n a ``unicode`` string will be returned.\n* Implemented ``write`` using a C extension module.\n\n1.2.7\n-----\n* Improved error messages when an error is encountered deserializing an\n expression.\n* Modified to work with Python 2.4.\n\n1.2.6\n-----\n\nThanks to Deron Meranda (author of ``demjson``) for his excellent `JSON\nlibrary comparison `_,\nwhich revealed many areas for improvement:\n\n* Use ``repr`` instead of ``unicode`` for serializing floating-point values,\n to avoid unnecessary rounding.\n* Fixed bug that prevented plus signs in an exponent from being parsed\n correctly.\n* Added support for serializing the following types:\n\n - ``generator``\n - ``set``\n - ``frozenset``\n - ``complex``, for values with no imaginary component.\n - ``array.array``\n - ``collections.deque``\n - ``collections.defaultdict``\n - ``UserList.UserList``\n - ``UserDict.UserDict``\n - ``UserString.UserString``\n\n* Raise an exception if a control character is encountered in a string.\n* Added support for detecting Unicode byte order marks in the auto decoder.\n* Allow only arrays and objects to be serialized directly. All other types\n must be contained within an array or object.\n* Stricter detection of whitespace.\n\nAlso includes some other miscellaneous fixes:\n\n* More reliable detection of ``Infinity`` and ``NaN`` on Windows.\n* Support for decoding UTF-32 on UCS2 builds of Python.\n* Faster detection of self-recursive containers.\n\n1.2.5\n-----\n* Return Unicode strings from ``write``, so the user can control the final\n encoding.\n* Prevent ``Infinity``, ``-Infinity``, and ``NaN`` from being serialized\n because JSON does not support these values.\n* Added ``coerce_keys`` parameter to ``write``. If ``True``, mapping keys\n will be coerced to strings. Defaults to ``False``.\n* Added ``ascii_only`` parameter to ``write``. If ``True``, non-ASCII\n codepoints will always be escaped to a \\u sequence. Defaults to ``True``.\n* Real detection of self-recursive container types.\n* Escape the solidus to prevent against `security issues\n `_.\n\n1.2.4\n-----\n* Fixed bug that prevented characters from being read after reading a\n Unicode escape sequence.\n* Moved test cases into ``jsonlib2.tests`` subpackage.\n\n1.2.3\n-----\n* Port to setuptools.\n* Corrected false positive in detection of illegal leading zeroes.\n\n1.2.2\n-----\n* Raise an exception if values in an object or array are not separated by\n commas.\n\n1.2.1\n-----\n* Support for building on Windows.\n\n1.2.0\n-----\n* Added ``sort_keys`` parameter to ``write``. This allows mapping types to\n be serialized to a predictable value, regardless of key ordering.\n* Added ``indent`` to ``write``. Any string passed as this value will be\n used for indentation. If the value is not `None`, pretty-printing will\n be activated.\n\n1.1.0\n-----\n* Support for reading astral Unicode codepoints on UCS2 builds of Python.\n\n1.0.0\n-----\n* Initial release.", "description_content_type": null, "docs_url": null, "download_url": "http://code.google.com/p/jsonlib2/downloads/list", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://code.google.com/p/jsonlib2/", "keywords": "json", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "jsonlib2", "package_url": "https://pypi.org/project/jsonlib2/", "platform": "Platform Independent", "project_url": "https://pypi.org/project/jsonlib2/", "project_urls": { "Download": "http://code.google.com/p/jsonlib2/downloads/list", "Homepage": "http://code.google.com/p/jsonlib2/" }, "release_url": "https://pypi.org/project/jsonlib2/1.5.2/", "requires_dist": null, "requires_python": null, "summary": "JSON serializer/deserializer for Python", "version": "1.5.2" }, "last_serial": 143436, "releases": { "1.4": [], "1.4.1": [], "1.4.2": [], "1.5": [], "1.5.1": [ { "comment_text": "", "digests": { "md5": "490dd65d35cb19a5caa0353599c6cb7e", "sha256": "ca329270ed8c81f92206108aa34249d0a1ed01bd98f0d74515526129defc126c" }, "downloads": -1, "filename": "jsonlib2-1.5.1.tar.gz", "has_sig": false, "md5_digest": "490dd65d35cb19a5caa0353599c6cb7e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 31333, "upload_time": "2009-06-11T20:08:54", "url": "https://files.pythonhosted.org/packages/7a/5e/ebb4bdee2d0839c711ffbf00c7fc3fbd3e8af3a83f651ad3816616b72118/jsonlib2-1.5.1.tar.gz" } ], "1.5.2": [ { "comment_text": "", "digests": { "md5": "f650c6979c04ed128e76edaa9ba50323", "sha256": "d806e241ee971e4747aac3a89cfea2db682f9f9fb1b028d8c3c4c695f0c0cce4" }, "downloads": -1, "filename": "jsonlib2-1.5.2.tar.gz", "has_sig": false, "md5_digest": "f650c6979c04ed128e76edaa9ba50323", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 31391, "upload_time": "2009-12-22T19:53:51", "url": "https://files.pythonhosted.org/packages/0e/1d/745b4e69ca0710215f7291ebbdfcdc95896dec7e196312b29d5a7c606038/jsonlib2-1.5.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f650c6979c04ed128e76edaa9ba50323", "sha256": "d806e241ee971e4747aac3a89cfea2db682f9f9fb1b028d8c3c4c695f0c0cce4" }, "downloads": -1, "filename": "jsonlib2-1.5.2.tar.gz", "has_sig": false, "md5_digest": "f650c6979c04ed128e76edaa9ba50323", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 31391, "upload_time": "2009-12-22T19:53:51", "url": "https://files.pythonhosted.org/packages/0e/1d/745b4e69ca0710215f7291ebbdfcdc95896dec7e196312b29d5a7c606038/jsonlib2-1.5.2.tar.gz" } ] }