{ "info": { "author": "Richard Jones", "author_email": "richard@cottagelabs.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "jsonurl\n=======\n\nIntroduction\n------------\n\njsonurl is a simple library for managing the serialisation and deserialisation of URL query strings which represent hierarchically structured data. \n\nIt will take python data structures which can be represented in JSON and convert them to flat key/value pairs for use in URL query strings, and it will take URL query strings and parse them into hierarchical data structures.\n\nThis is convenient if you wish to pass structured data around in the URL itself rather than in a POST body. This may complement a web API which also accepts JSON strings in the body of a POST request, providing equivalent functionality using GET without constructing URLs which include url-encoded json objects.\n\n\nUsage\n-----\n\n >>> import jsonurl\n\n### Converting Data Structures\n\nA simple flat dictionary\n\n >>> d = {\"one\" : 1, \"two\" : 2}\n \n >>> jsonurl.query_string(d)\n 'one=1&two=2'\n\nA dictionary with a nested dictionary\n\n >>> d = {\"one\" : {\"two\" : 2, \"three\" : 3}, \"four\" : 4}\n >>> q = jsonurl.query_string(d)\n >>> q\n 'four=4&one.three=3&one.two=2'\n\nWe can also get a flat dictionary as a proxy for the hierarchic one, if we do not want jsonurl to actually prepare the query part of the URL for us\n\n >>> jsonurl.dict_to_args(d)\n {'four': '4', 'one.three': '3', 'one.two': '2'}\n\nWe can parse the query string back into a python dictionary object\n\n >>> jsonurl.parse_query(q)\n {'four': 4, 'one': {'three': 3, 'two': 2}}\n\nWe can also serialise nested lists:\n\n >>> d = {\"one\" : 1, \"two\" : [2,3,4]}\n\nThe flattened data structure:\n\n >>> jsonurl.dict_to_args(d)\n {'two.1': '3', 'two.0': '2', 'two.2': '4', 'one': '1'}\n\nThe query string itself:\n\n >>> q = jsonurl.query_string(d)\n >>> q\n 'one=1&two.0=2&two.1=3&two.2=4'\n\nThis can be comfortably parsed back into a python data structure\n\n >>> jsonurl.parse_query(q)\n {'two': [2, 3, 4], 'one': 1}\n\nWe can go on to serialise arbitrarily complex data structures\n\n >>> d = {\"one\" : [ {\"two\" : 2, \"three\" : 3}, 4 ]}\n >>> q = jsonurl.query_string(d)\n >>> q\n 'one.0.three=3&one.0.two=2&one.1=4'\n\n### Escape Characters\n\njsonurl will also handle url-escaping:\n\n >>> q = {\"escape_me\" : \"I'll need escaping\"}\n >>> s = jsonurl.query_string(q)\n >>> s\n 'escape_me=I%27ll+need+escaping'\n\njsonurl uses \"+\" for a space instead of %20 to improve readability\n\nIt also unescapes everything during parse:\n\n >>> jsonurl.parse_query(s)\n {'escape_me': \"I'll need escaping\"}\n\nSince jsonurl uses \".\" as its separator, dictionary keys with \".\" in the name are escaped. We prefix each \".\" with another during serialisation:\n\n >>> d = {\"user.names\" : [\"richard\", \"jones\"]}\n >>> q = jsonurl.query_string(d)\n >>> q\n 'user..names.0=richard&user..names.1=jones'\n\n\"..\" is then converted back during parsing:\n\n >>> jsonurl.parse_query(q)\n {'user.names': ['richard', 'jones']}\n\n\n### Parameter Ordering\n\nIt orders the query parameters, to make it easier to read long query strings:\n\n >>> d = {\"b\" : \"last\", \"a\" : [1,2,3]}\n >>> jsonurl.query_string(d)\n 'a.0=1&a.1=2&a.2=3&b=last'\n\n", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "UNKNOWN", "keywords": null, "license": "CC0", "maintainer": null, "maintainer_email": null, "name": "jsonurl", "package_url": "https://pypi.org/project/jsonurl/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/jsonurl/", "project_urls": { "Download": "UNKNOWN", "Homepage": "UNKNOWN" }, "release_url": "https://pypi.org/project/jsonurl/1.0.0/", "requires_dist": null, "requires_python": null, "summary": "A library for serialising and deserialising URL query strings which can represent\n hierarchical data structures which can also be represented as JSON. \n \n This is convenient, for example, if you wish to have a web API which takes JSON \n objects as a POST body, but which may also need to respond to GET requests for \n which a more readable set of parameters would be appropriate.", "version": "1.0.0" }, "last_serial": 793839, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "6bfc6162d37c67142abe75384af43bfa", "sha256": "277c5206f8d8bde5d624e3832c64064513d55b24a87f255ddcaca4dfc03e6028" }, "downloads": -1, "filename": "jsonurl-1.0.0.tar.gz", "has_sig": false, "md5_digest": "6bfc6162d37c67142abe75384af43bfa", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3147, "upload_time": "2012-03-14T17:08:33", "url": "https://files.pythonhosted.org/packages/32/e1/8fd6eae5ada3ce416ed8a8cf6218b986099731b66536c12ee2fda018339c/jsonurl-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6bfc6162d37c67142abe75384af43bfa", "sha256": "277c5206f8d8bde5d624e3832c64064513d55b24a87f255ddcaca4dfc03e6028" }, "downloads": -1, "filename": "jsonurl-1.0.0.tar.gz", "has_sig": false, "md5_digest": "6bfc6162d37c67142abe75384af43bfa", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3147, "upload_time": "2012-03-14T17:08:33", "url": "https://files.pythonhosted.org/packages/32/e1/8fd6eae5ada3ce416ed8a8cf6218b986099731b66536c12ee2fda018339c/jsonurl-1.0.0.tar.gz" } ] }