{ "info": { "author": "Scott Maxwell", "author_email": "scott@codecobblers.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: Academic Free License (AFL)", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.5", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": ":mod:`dirtyjson` --- JSON decoder\n=================================\n\n.. module:: dirtyjson\n :synopsis: Decode JSON data from dirty files.\n.. moduleauthor:: Scott Maxwell \n\nJSON (JavaScript Object Notation) is a subset of JavaScript\nsyntax (ECMA-262 3rd edition) used as a lightweight data interchange format.\n\n:mod:`dirtyjson` is a JSON decoder meant for extracting JSON-type data from .js\nfiles. The returned data structure includes information about line and column\nnumbers, so you can output more useful error messages. The input can also\ninclude single quotes, line comments, inline comments, dangling commas,\nunquoted single-word keys, and hexadecimal and octal numbers.\n\nThe goal of :mod:`dirtyjson` is to read JSON objects out of files that are\nlittered with elements that do not fit the official JSON standard. By providing\nline and column number contexts, a dirty JSON file can be used as source input\nfor a complex data parser or compiler.\n\n:mod:`dirtyjson` exposes an API familiar to users of the standard library\n:mod:`marshal` and :mod:`pickle` modules. However, :mod:`dirtyjson` provides\nonly the `load(s)` capability. To write JSON, use either the standard\n:mod:`json` library or :mod:`simplejson`.\n\n.. note::\n\n The code for :mod:`dirtyjson` is a fairly drastically rewritten version\n of the loader in :mod:`simplejson` so thanks go to Bob Ippolito of the\n :mod:`simplejson` project for providing such a nice starting point.\n\nDevelopment of dirtyjson happens on Github:\nhttps://github.com/codecobblers/dirtyjson\n\nDecoding JSON and getting position information::\n\n >>> import dirtyjson\n >>> obj = [u'foo', {u'bar': [u'baz', None, 1.0, 2]}]\n >>> d = dirtyjson.loads(\"\"\"[\"foo\", /* not fu*/ {bar: ['baz', null, 1.0, 2,]}] and then ignore this junk\"\"\")\n >>> d == obj\n True\n >>> pos = d.attributes(0) # line/column position of first element in array\n >>> pos.line == 1\n True\n >>> pos.column == 2\n True\n >>> pos = d[1].attributes('bar') # line/column position of 'bar' key/value pair\n >>> pos.key.line == 1\n True\n >>> pos.key.column == 22\n True\n >>> pos.value.line == 1\n True\n >>> pos.value.column == 27\n True\n\nDecoding unicode from JSON::\n\n >>> dirtyjson.loads('\"\\\\\"foo\\\\bar\"') == u'\"foo\\x08ar'\n True\n\nDecoding JSON from streams::\n\n >>> from dirtyjson.compat import StringIO\n >>> io = StringIO('[\"streaming API\"]')\n >>> dirtyjson.load(io)[0] == 'streaming API'\n True\n\nUsing Decimal instead of float::\n\n >>> import dirtyjson\n >>> from decimal import Decimal\n >>> dirtyjson.loads('1.1', parse_float=Decimal) == Decimal('1.1')\n True\n\n\nBasic Usage\n-----------\n\n.. function:: load(fp[, encoding[, parse_float[, parse_int[, parse_constant[, search_for_first_object]]]]])\n\n Performs the following translations in decoding by default:\n\n +---------------+-------------------------+\n | JSON | Python |\n +===============+=========================+\n | object | :class:`AttributedDict` |\n +---------------+-------------------------+\n | array | :class:`AttributedList` |\n +---------------+-------------------------+\n | string | unicode |\n +---------------+-------------------------+\n | number (int) | int, long |\n +---------------+-------------------------+\n | number (real) | float |\n +---------------+-------------------------+\n | true | True |\n +---------------+-------------------------+\n | false | False |\n +---------------+-------------------------+\n | null | None |\n +---------------+-------------------------+\n\n It also understands ``NaN``, ``Infinity``, and ``-Infinity`` as their\n corresponding ``float`` values, which is outside the JSON spec.\n\n Deserialize *fp* (a ``.read()``-supporting file-like object containing a JSON\n document) to a Python object. :exc:`dirtyjson.Error` will be\n raised if the given document is not valid.\n\n If the contents of *fp* are encoded with an ASCII based encoding other than\n UTF-8 (e.g. latin-1), then an appropriate *encoding* name must be specified.\n Encodings that are not ASCII based (such as UCS-2) are not allowed, and\n should be wrapped with ``codecs.getreader(fp)(encoding)``, or simply decoded\n to a :class:`unicode` object and passed to :func:`loads`. The default\n setting of ``'utf-8'`` is fastest and should be using whenever possible.\n\n If *fp.read()* returns :class:`str` then decoded JSON strings that contain\n only ASCII characters may be parsed as :class:`str` for performance and\n memory reasons. If your code expects only :class:`unicode` the appropriate\n solution is to wrap fp with a reader as demonstrated above.\n\n *parse_float*, if specified, will be called with the string of every JSON\n float to be decoded. By default, this is equivalent to ``float(num_str)``.\n This can be used to use another datatype or parser for JSON floats\n (e.g. :class:`decimal.Decimal`).\n\n *parse_int*, if specified, will be called with the int of the string of every\n JSON int to be decoded. By default, this is equivalent to ``int(num_str)``.\n This can be used to use another datatype or parser for JSON integers\n (e.g. :class:`float`).\n\n .. note::\n\n Unlike the standard :mod:`json` module, :mod:`dirtyjson` always does\n ``int(num_str, 0)`` before passing through to the converter passed is as\n the *parse_int* parameter. This is to enable automatic handling of hex\n and octal numbers.\n\n *parse_constant*, if specified, will be called with one of the following\n strings: ``true``, ``false``, ``null``, ``'-Infinity'``, ``'Infinity'``,\n ``'NaN'``. This can be used to raise an exception if invalid JSON numbers are\n encountered or to provide alternate values for any of these constants.\n\n *search_for_first_object*, if ``True``, will cause the parser to search for\n the first occurrence of either ``{`` or ``[``. This is very useful for\n reading an object from a JavaScript file.\n\n.. function:: loads(s[, encoding[, parse_float[, parse_int[, parse_constant[, search_for_first_object[, start_index]]]]])\n\n Deserialize *s* (a :class:`str` or :class:`unicode` instance containing a JSON\n document) to a Python object. :exc:`dirtyjson.Error` will be\n raised if the given JSON document is not valid.\n\n If *s* is a :class:`str` instance and is encoded with an ASCII based encoding\n other than UTF-8 (e.g. latin-1), then an appropriate *encoding* name must be\n specified. Encodings that are not ASCII based (such as UCS-2) are not\n allowed and should be decoded to :class:`unicode` first.\n\n If *s* is a :class:`str` then decoded JSON strings that contain\n only ASCII characters may be parsed as :class:`str` for performance and\n memory reasons. If your code expects only :class:`unicode` the appropriate\n solution is decode *s* to :class:`unicode` prior to calling loads.\n\n *start_index*, if non-zero, will cause the parser to start processing from\n the specified offset, while maintaining the correct line and column numbers.\n This is very useful for reading an object from the middle of a JavaScript\n file.\n\n The other arguments have the same meaning as in :func:`load`.\n\nExceptions\n----------\n\n.. exception:: dirtyjson.Error(msg, doc, pos)\n\n Subclass of :exc:`ValueError` with the following additional attributes:\n\n .. attribute:: msg\n\n The unformatted error message\n\n .. attribute:: doc\n\n The JSON document being parsed\n\n .. attribute:: pos\n\n The start index of doc where parsing failed\n\n .. attribute:: lineno\n\n The line corresponding to pos\n\n .. attribute:: colno\n\n The column corresponding to pos\n\nAttributedDict and AttributedList\n---------------------------------\n\nThe :mod:`dirtyjson` module uses :class:`AttributedDict` and\n:class:`AttributedList` instead of ``dict`` and ``list``. Each is actually a\nsubclass of its base type (``dict`` or ``list``) and can be used as if they were\nthe standard class, but these have been enhanced to store attributes with each\nelement. We use those attributes to store line and column numbers. You can use\nthat information to refer users back to the exact location in the original\nsource file.\n\n.. class:: Position()\n\n This is a very simple utility class that contains ``line`` and ``column``.\n It is used for storing the position attributes for :class:`AttributedList`\n and :class:`KeyValuePosition`\n\n.. class:: KeyValuePosition()\n\n This is another very simple utility class that contains ``key`` and\n ``value``. Each of those is a :class:`Position` object specifying the\n location in the original source string/file of the key and value. It is used\n for storing the position attributes for :class:`AttributedDict`.\n\n.. class:: AttributedDict()\n\n A subclass of ``dict`` that behaves exactly like a ``dict`` except that it\n maintains order like an ``OrderedDict`` and allows storing attributes for\n each key/value pair.\n\n .. method:: add_with_attributes(self, key, value, attributes)\n\n Set the *key* in the underlying ``dict`` to the *value* and also store\n whatever is passed in as *attributes* for later retrieval. In our case,\n we store :class:`KeyValuePosition`.\n\n .. method:: attributes(self, key)\n\n Return the attributes associated with the specified *key* or ``None`` if\n no attributes exist for the key. In our case, we store\n :class:`KeyValuePosition`. Retrieve position info like this::\n\n pos = d.attributes(key)\n key_line = pos.key.line\n key_column = pos.key.column\n value_line = pos.value.line\n value_column = pos.value.column\n\n.. class:: AttributedList()\n\n A subclass of ``list`` that behaves exactly like a ``list`` except that it\n allows storing attributes for each value.\n\n .. method:: append(self, value, attributes=None):\n\n Appends *value* to the list and *attributes* to the associated location.\n In our case, we store :class:`Position`.\n\n .. method:: attributes(self, index)\n\n Returns the attributes for the value at the given *index*. In our case,\n we store :class:`Position`. Retrieve position info like this::\n\n pos = l.attributes(index)\n value_line = pos.line\n value_column = pos.column\n\n .. note::\n\n This class is *NOT* robust. If you insert or delete items, the attributes\n will get out of sync. Making this a non-naive class would be a nice\n enhancement.", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/codecobblers/dirtyjson", "keywords": "", "license": "MIT License", "maintainer": "", "maintainer_email": "", "name": "dirtyjson", "package_url": "https://pypi.org/project/dirtyjson/", "platform": "any", "project_url": "https://pypi.org/project/dirtyjson/", "project_urls": { "Homepage": "https://github.com/codecobblers/dirtyjson" }, "release_url": "https://pypi.org/project/dirtyjson/1.0.7/", "requires_dist": null, "requires_python": "", "summary": "JSON decoder for Python that can extract data from the muck", "version": "1.0.7" }, "last_serial": 3050761, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "b2fed9fc168044151a16f54b7ec86683", "sha256": "6826e6f324e52004f4b0b560d38a0dec4fde93487650b462810f6e47eaf11a86" }, "downloads": -1, "filename": "dirtyjson-1.0.0.tar.gz", "has_sig": false, "md5_digest": "b2fed9fc168044151a16f54b7ec86683", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23864, "upload_time": "2015-01-07T23:13:42", "url": "https://files.pythonhosted.org/packages/b1/ef/048d98a00d6d19795d23d3b7a6ddfff107101ca77fc529a6c598e1aff846/dirtyjson-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "02b28a4eef2ef4c7a53027b4ed89679a", "sha256": "2cbb3c68913b23ec498ff737e34122d37aafa6a911df16f22e1380ae07e4065b" }, "downloads": -1, "filename": "dirtyjson-1.0.1.tar.gz", "has_sig": false, "md5_digest": "02b28a4eef2ef4c7a53027b4ed89679a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23780, "upload_time": "2015-01-07T23:46:11", "url": "https://files.pythonhosted.org/packages/18/d2/9630f6c479cc9075bd7735dd15c04c74ee1bca211bc1cef1e665d7346f8f/dirtyjson-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "93ba914400f9917963c48c149c0546a4", "sha256": "4255b53ebfde64c7475963bbd878a048692ffd6e04e3c2f5f1779a9d9036fe23" }, "downloads": -1, "filename": "dirtyjson-1.0.2.tar.gz", "has_sig": false, "md5_digest": "93ba914400f9917963c48c149c0546a4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23804, "upload_time": "2015-01-08T19:10:44", "url": "https://files.pythonhosted.org/packages/1d/dd/144ffceff358939721c0348ce439400ce276fe86216161a3d029dafc0857/dirtyjson-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "50e98bd2a71669480122a54cdad1d3fd", "sha256": "60a60bfbee5020706a7c3ec8a3281353821ea7a7b349d7526053e77bcbd10c02" }, "downloads": -1, "filename": "dirtyjson-1.0.3.tar.gz", "has_sig": false, "md5_digest": "50e98bd2a71669480122a54cdad1d3fd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 24481, "upload_time": "2015-01-08T20:06:37", "url": "https://files.pythonhosted.org/packages/63/f0/3bd0c38b0401cece49639f2723a07be426e8ed0324615af92f36822618bc/dirtyjson-1.0.3.tar.gz" } ], "1.0.7": [ { "comment_text": "", "digests": { "md5": "28235786cd35c77851e7844e4d8573de", "sha256": "b1d1e457b5432fd53283eb0341b2a273690a8b6bb9090689d2cd6a776f57efe7" }, "downloads": -1, "filename": "dirtyjson-1.0.7.tar.gz", "has_sig": false, "md5_digest": "28235786cd35c77851e7844e4d8573de", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 25351, "upload_time": "2017-07-26T18:38:17", "url": "https://files.pythonhosted.org/packages/94/5c/aad7fffd803411a9d616bfbf6b9994a26e6179235c4a3f6c44a4913a2013/dirtyjson-1.0.7.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "28235786cd35c77851e7844e4d8573de", "sha256": "b1d1e457b5432fd53283eb0341b2a273690a8b6bb9090689d2cd6a776f57efe7" }, "downloads": -1, "filename": "dirtyjson-1.0.7.tar.gz", "has_sig": false, "md5_digest": "28235786cd35c77851e7844e4d8573de", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 25351, "upload_time": "2017-07-26T18:38:17", "url": "https://files.pythonhosted.org/packages/94/5c/aad7fffd803411a9d616bfbf6b9994a26e6179235c4a3f6c44a4913a2013/dirtyjson-1.0.7.tar.gz" } ] }