{
"info": {
"author": "Robert Parelius",
"author_email": "rparelius@gmail.com",
"bugtrack_url": null,
"classifiers": [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python"
],
"description": "# lxml2json\n\n**lxml2json is a python package that converts XML elements into their JSON equivalent, and vice versa. \nThere are many options to convert the data to a desired format:**\n- **rename tags**\n- **ignore elements**\n- **move elements within the tree**\n- **always represent data as lists**\n- **supply value to give empty elements**\n\n\n\n**Installation:**\n\n pip install lxml2json\n\n\n\n**Usage:**\n\n from lxml2json import convert\n from pprint import pprint as pp\n\n xml = '''\n \n a\n b\n c\n \n d\n e\n f\n \n \n g\n h\n i\n \n \n j\n k\n l\n \n \n '''\n\n d = convert(xml)\n pp(d)\n {'parent': {'c1': ['a', 'b', 'c'],\n 'c2': [{'gc1': 'd', 'gc2': 'e', 'gc3': 'f'},\n {'gc1': 'g', 'gc2': 'h', 'gc3': 'i'}],\n 'c3': {'gc1': ['j', 'k', 'l']},\n 'c4': None}}\n\n\n\n\n## Options\n\nlxml2json provides the following optional arguments to modify conversion behavior or output data format::\n\n- **ordered:** Boolean, defaults to False. Specifies whether to generate output as an OrderedDict.\n\n- **noText:** Defaults to None. Specifies the value to give to elements that contain no children and no text value.\n\n- **alwaysList:** Defaults to None. Allows specification of xpath queries to apply to the inputted XML element that will\n cause all matched elements to be stored as lists. This is useful for creating a deterministic data structure.\n See below for an example.\n\n- **ignore:** Defaults to None. Allows specification of xpath queries to apply to the inputted XML element that will cause\n all matched elements to be ignored.\n\n- **rename:** Defaults to None. Allows renaming tags by supplying tuples/lists of tuples containing xpath queries to match elements, along\n with a string specifying the desired tag. See below for example.\n\n- **move:** Defaults to None. Provides the option to move elements to a desired place within the hierarchy. Use case: flattening\n a deeply nested structure. Requires tuples/lists of tuples containing xpath queries for matching elements, along with xpath queries\n (relative to the matched element's location) of where to move the element. See below for example\n\nThe order of operations is: move, rename, ignore. This allows you to essentially replace an element with a subelement by moving the subelement to the same level of hierarchy, renaming the original element, then ignoring it.\n\n\n## alwaysList\n\nlxml2json's processing logic will always attempt to represent an element as a dictionary, **unless there are multiple\nsibling elements with the same tag**, in which case it must represent the object as a list, since dictionaries require unique keys.\n\nThis creates the possibility of variance within the overall json data structure, since some portions of the xml may be represented as lists and\nother sections with the same tag may be represented as dictionaries or text values, depending on the number of siblings with the same tag.\n\n**Consider the following example:**\n\n >>> from lxml2json import convert\n >>> from pprint import pprint as pp\n >>> \n >>> xml = '''\n ... \n ... \n ... 1\n ... 2\n ... 3\n ... \n ... \n ... 4\n ... 5\n ... 6\n ... \n ... \n ... 7\n ... \n ... \n ... '''\n >>>\n\n**By default, lxml2json will represent this xml object as:**\n\n >>> pp(convert(xml))\n {'parent': {'c1': {'num': ['1', '2', '3']},\n 'c2': {'num': ['4', '5', '6']},\n 'c3': {'num': '7'}}}\n\n\nNotice that the values for 'num' key are contained in a **list** for the first 2 instances, but for the last it is just its native value of seven.\nThis behavior is expected, and for many situations functions perfectly well as a representation of the xml structure. However, it can present\nchallenges when iterating over the resultant json object, as additional logic may be necessary to handle whether the values are contained in a list or not.\n\nTo allow for a more deterministic structure, lxml2json allows you to supply xpath queries that it will apply to the inputted xml, resulting in any matching elements\nbeing stored as lists, regardless of the number of identical sibling tags.\n\nIn this example, the xpath query: **\".//num\"** will match all the 'num' elements, resulting in all such elements storing their values in a list.\n\n**Let us see this in action:**\n\n\n >>> \n >>> pp(convert(xml, alwaysList=\".//num\"))\n {'parent': {'c1': {'num': ['1', '2', '3']},\n 'c2': {'num': ['4', '5', '6']},\n 'c3': {'num': ['7']}}}\n >>> \n\n\nNotice that the 3rd 'num' value is now a list, similar to the first 2 instances.\n\nYou can supply as many xpath queries as you like, either as a list of queries, or a string of comma-separated values. In either case, the matching elements will be flagged.\n\n\n\n## ignore\n\nThe 'ignore' option allows specifying elements to ignore. \nExample:\n\n >>> from lxml2json import convert\n >>> from pprint import pprint as pp\n >>>\n xml = '''\n \n \n Thomas\n Robert\n Karen\n \n \n '''\n >>> \n >>> pp(convert(xml))\n {'parent': {'son': {'granddaughter': 'Karen',\n 'grandson': ['Thomas', 'Robert']}}}\n >>> \n >>> pp(convert(xml, ignore=\".//granddaughter\"))\n {'parent': {'son': {'grandson': ['Thomas', 'Robert']}}}\n >>> \n\nBy specifiying the xpath query \".//grandaughter\", lxml2json will ignore any elements with that tag when converting.\n\n\n## move\n\nThe 'move' option allows for mutation of the data structure to match a desired state. One use-case is to 'flatten' the nesting structure. \n\nRequires providing a tuple/list of tuples, each containing an xpath query to match elements along with a corresponding xpath query (relative to the location of the matched element) specifying where in the hierarchy to move the data.\n\nExample:\n\n\n xml = \"\"\"\n \n \n Joey\n 7\n \n \n \n legos\n playstation\n bike\n \n \n \n \n \"\"\"\n\n #default result\n >>> pp(convert(xml))\n {'children': {'child': {'age': '7',\n 'favorite': {'things': {'toys': {'toy': ['legos',\n 'playstation',\n 'bike']}}},\n 'name': 'Joey'}}}\n >>> \n\n #perhaps we want a flattened child dictionary\n >>> pp(convert(xml, move=(\".//toy\", \"./../../../..\"), ignore=\".//favorite\"))\n {'children': {'child': {'age': '7',\n 'name': 'Joey',\n 'toy': ['legos', 'playstation', 'bike']}}}\n\n\n\n## Converting from JSON to XML\n\nlxml2json provides a 'reverse' function that generates an XML element (or string) for an inputted dictionary object.\n\nNote: if the inputted dictionary has multiple top-level k:v pairs, or if the value of the top-level key is a list, then a 'root' element is created so as to allow for a properly\nformatted xml structure, which requires a single root element.\n\n**Options**\n\nThere is a single boolean option: 'text', which defaults to False. When set to True, the reverse function will output a pretty-printed string of the xml element created.\n\n\n\n\n\n\n\n\n",
"description_content_type": "text/markdown",
"docs_url": null,
"download_url": "",
"downloads": {
"last_day": -1,
"last_month": -1,
"last_week": -1
},
"home_page": "https://github.com/rparelius/lxml2json",
"keywords": "",
"license": "",
"maintainer": "",
"maintainer_email": "",
"name": "lxml2json",
"package_url": "https://pypi.org/project/lxml2json/",
"platform": "",
"project_url": "https://pypi.org/project/lxml2json/",
"project_urls": {
"Homepage": "https://github.com/rparelius/lxml2json"
},
"release_url": "https://pypi.org/project/lxml2json/0.2.5/",
"requires_dist": [
"lxml"
],
"requires_python": "",
"summary": "converts XML elements into their JSON equivalent or vice versa",
"version": "0.2.5"
},
"last_serial": 4927963,
"releases": {
"0.1.0": [
{
"comment_text": "",
"digests": {
"md5": "22a74d149a7efb2a30a3d936ac3e7451",
"sha256": "a5cc092b820488e4cc07f2ee44b34ad346ede16102720df463483fe37ad90683"
},
"downloads": -1,
"filename": "lxml2json-0.1.0-py2-none-any.whl",
"has_sig": false,
"md5_digest": "22a74d149a7efb2a30a3d936ac3e7451",
"packagetype": "bdist_wheel",
"python_version": "py2",
"requires_python": null,
"size": 4076,
"upload_time": "2018-09-04T15:21:39",
"url": "https://files.pythonhosted.org/packages/d1/98/0dc54626895afbc15f2a688ed469c303e9fb93de4a17a4d54782226ec9c4/lxml2json-0.1.0-py2-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "9452d05ff7eafde7ba3387647cf09c5a",
"sha256": "f80469dab5b64c3819e2f9e40247c051724168bc584cadf6e3623dc53efc2748"
},
"downloads": -1,
"filename": "lxml2json-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "9452d05ff7eafde7ba3387647cf09c5a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3576,
"upload_time": "2018-09-04T15:21:41",
"url": "https://files.pythonhosted.org/packages/a4/39/1adab44c1806c7d24732aa3b6246cbd8f0f7ea2d361d4fcebd59deaa0f44/lxml2json-0.1.0.tar.gz"
}
],
"0.2.0": [
{
"comment_text": "",
"digests": {
"md5": "7fd58ffb98f1c68f8ccf4e64731d994c",
"sha256": "b2f4da9c3f18a3e8ad4876d6e5f6bdb5dc354e9a690a3ef0430d83335166aebe"
},
"downloads": -1,
"filename": "lxml2json-0.2.0-py2-none-any.whl",
"has_sig": false,
"md5_digest": "7fd58ffb98f1c68f8ccf4e64731d994c",
"packagetype": "bdist_wheel",
"python_version": "py2",
"requires_python": null,
"size": 3556,
"upload_time": "2018-09-05T18:32:47",
"url": "https://files.pythonhosted.org/packages/03/e7/fde8d6bff2494626cb8996a851474f760e1816dc8607287e2d50665e88a0/lxml2json-0.2.0-py2-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "b79d6014cfd57c0fe97fcd6594439a87",
"sha256": "3674acb427a3bae57dab46594020b0d0a0004868597be42dc8b32b7822db8ec2"
},
"downloads": -1,
"filename": "lxml2json-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "b79d6014cfd57c0fe97fcd6594439a87",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3128,
"upload_time": "2018-09-05T18:32:48",
"url": "https://files.pythonhosted.org/packages/ed/61/f62556caa5e5760198086745412f32fafe3ce4971f9be44dd11099bd0f92/lxml2json-0.2.0.tar.gz"
}
],
"0.2.1": [
{
"comment_text": "",
"digests": {
"md5": "9efca120ea1084cbf7a1a14b2e95dbd0",
"sha256": "4d518570ef25735046cd481e7398af9df3e999ca63254780cc6e9a3e3a9f3cdf"
},
"downloads": -1,
"filename": "lxml2json-0.2.1-py2-none-any.whl",
"has_sig": false,
"md5_digest": "9efca120ea1084cbf7a1a14b2e95dbd0",
"packagetype": "bdist_wheel",
"python_version": "py2",
"requires_python": null,
"size": 5134,
"upload_time": "2018-09-11T17:18:16",
"url": "https://files.pythonhosted.org/packages/9d/0e/beba6fce85983b05b8d1d8bdfeee1c63bac7d75a5a1f82a06ca36e14e32f/lxml2json-0.2.1-py2-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "e358f2c2c11cb556e91a9c550cbfc0cc",
"sha256": "81fabc6213be3e98bf94d4320f74bf9a52ca770ea10658551a99f49d3854b086"
},
"downloads": -1,
"filename": "lxml2json-0.2.1.tar.gz",
"has_sig": false,
"md5_digest": "e358f2c2c11cb556e91a9c550cbfc0cc",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4883,
"upload_time": "2018-09-11T17:18:17",
"url": "https://files.pythonhosted.org/packages/e0/49/0868df10974b89b6e0f52331db4453b82ea0eaf91801a07c38f4af1bf369/lxml2json-0.2.1.tar.gz"
}
],
"0.2.2": [
{
"comment_text": "",
"digests": {
"md5": "ed3cdf464d64a6babc47d925446c22b6",
"sha256": "d70872ed5c8c4661fc936812aa8f17605c7c03b842a0ed336c8ccc0a5b77b295"
},
"downloads": -1,
"filename": "lxml2json-0.2.2-py2-none-any.whl",
"has_sig": false,
"md5_digest": "ed3cdf464d64a6babc47d925446c22b6",
"packagetype": "bdist_wheel",
"python_version": "py2",
"requires_python": null,
"size": 5854,
"upload_time": "2018-10-16T15:21:08",
"url": "https://files.pythonhosted.org/packages/7f/42/6cd4c4c35456523ae13ac7f74573f4e8b53aca32d3d35ed9b5e0f73ee902/lxml2json-0.2.2-py2-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "4683b3a6d85d3cc4b722d0ffc0e25372",
"sha256": "5e879d8a0a452b51c5014bdbc9c95516bfb4429e681c3929f884338421021bb4"
},
"downloads": -1,
"filename": "lxml2json-0.2.2.tar.gz",
"has_sig": false,
"md5_digest": "4683b3a6d85d3cc4b722d0ffc0e25372",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5644,
"upload_time": "2018-10-16T15:21:10",
"url": "https://files.pythonhosted.org/packages/66/7c/932ad4a5b4e836324191cf232492742084e946c81fd1e465f74af4e90649/lxml2json-0.2.2.tar.gz"
}
],
"0.2.3": [
{
"comment_text": "",
"digests": {
"md5": "7ef30fc291e87b5bd4b025e03c338ce7",
"sha256": "32dc8247981429d7a74e95998618e3a08b25f171038344c02e960bc56bd8a7db"
},
"downloads": -1,
"filename": "lxml2json-0.2.3-py2-none-any.whl",
"has_sig": false,
"md5_digest": "7ef30fc291e87b5bd4b025e03c338ce7",
"packagetype": "bdist_wheel",
"python_version": "py2",
"requires_python": null,
"size": 5851,
"upload_time": "2018-10-17T16:24:50",
"url": "https://files.pythonhosted.org/packages/c8/da/9d6188be94934201fbe6ebf970b9bfad92aefea33fbc39d1005bdd652eca/lxml2json-0.2.3-py2-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "c96ab90954eb766644eceda9b0ff8c30",
"sha256": "295e2cac9f9a1d6b5a9b59c85fcabceb67ac0872f94ccb423c12040142cdd4e7"
},
"downloads": -1,
"filename": "lxml2json-0.2.3.tar.gz",
"has_sig": false,
"md5_digest": "c96ab90954eb766644eceda9b0ff8c30",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5636,
"upload_time": "2018-10-17T16:24:51",
"url": "https://files.pythonhosted.org/packages/cd/b9/3afd15b098b4f1fadc0ffbe62a4a969c17c14783c4adb5e3a3548dc1634c/lxml2json-0.2.3.tar.gz"
}
],
"0.2.4": [
{
"comment_text": "",
"digests": {
"md5": "786db74dcfa0f28288067b995666c310",
"sha256": "509145badf3ced18bd69b68019a6cd224cc792760c3f8da31ef48e625f3636d5"
},
"downloads": -1,
"filename": "lxml2json-0.2.4-py2-none-any.whl",
"has_sig": false,
"md5_digest": "786db74dcfa0f28288067b995666c310",
"packagetype": "bdist_wheel",
"python_version": "py2",
"requires_python": null,
"size": 5982,
"upload_time": "2018-12-12T19:22:35",
"url": "https://files.pythonhosted.org/packages/0c/08/6a07daf9983b7a5e76a6cf1638d9c997fd86ad84c8743f0a256df693d058/lxml2json-0.2.4-py2-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "7bb0d5c8ac722bf059a5eb4a9e24d419",
"sha256": "2f65431155239bf12bbe44ed5836e7331ed0c14b31f6640d1a18d7414fff74d1"
},
"downloads": -1,
"filename": "lxml2json-0.2.4.tar.gz",
"has_sig": false,
"md5_digest": "7bb0d5c8ac722bf059a5eb4a9e24d419",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5766,
"upload_time": "2018-12-12T19:22:37",
"url": "https://files.pythonhosted.org/packages/cc/47/c018ee02484ddb0d516189a986438e353858054d2241fe58974583a0756f/lxml2json-0.2.4.tar.gz"
}
],
"0.2.5": [
{
"comment_text": "",
"digests": {
"md5": "645b0c89388a32c47961604f65bba995",
"sha256": "67b4668293a2dbdf09b5693d97cff0d722808b01227f1fb290570c90bc100890"
},
"downloads": -1,
"filename": "lxml2json-0.2.5-py2-none-any.whl",
"has_sig": false,
"md5_digest": "645b0c89388a32c47961604f65bba995",
"packagetype": "bdist_wheel",
"python_version": "py2",
"requires_python": null,
"size": 8199,
"upload_time": "2019-03-12T01:30:42",
"url": "https://files.pythonhosted.org/packages/c6/78/9fd8ab552e7dbb84c4cc1cede7ca71fcb7420410c96ecd5a2f4519745527/lxml2json-0.2.5-py2-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "eb38d02f00dd372ee3ba67abd2a93c31",
"sha256": "51ecf04b25ef86bf2cea22de9d3790710c47033333ba0c3a898901237b9c65fd"
},
"downloads": -1,
"filename": "lxml2json-0.2.5.tar.gz",
"has_sig": false,
"md5_digest": "eb38d02f00dd372ee3ba67abd2a93c31",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 7500,
"upload_time": "2019-03-12T01:30:44",
"url": "https://files.pythonhosted.org/packages/fb/05/e4b8ce5f80cbc724bfe0cd0bbbc0e7798457ab0710197ffe9822e82ed6a8/lxml2json-0.2.5.tar.gz"
}
]
},
"urls": [
{
"comment_text": "",
"digests": {
"md5": "645b0c89388a32c47961604f65bba995",
"sha256": "67b4668293a2dbdf09b5693d97cff0d722808b01227f1fb290570c90bc100890"
},
"downloads": -1,
"filename": "lxml2json-0.2.5-py2-none-any.whl",
"has_sig": false,
"md5_digest": "645b0c89388a32c47961604f65bba995",
"packagetype": "bdist_wheel",
"python_version": "py2",
"requires_python": null,
"size": 8199,
"upload_time": "2019-03-12T01:30:42",
"url": "https://files.pythonhosted.org/packages/c6/78/9fd8ab552e7dbb84c4cc1cede7ca71fcb7420410c96ecd5a2f4519745527/lxml2json-0.2.5-py2-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "eb38d02f00dd372ee3ba67abd2a93c31",
"sha256": "51ecf04b25ef86bf2cea22de9d3790710c47033333ba0c3a898901237b9c65fd"
},
"downloads": -1,
"filename": "lxml2json-0.2.5.tar.gz",
"has_sig": false,
"md5_digest": "eb38d02f00dd372ee3ba67abd2a93c31",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 7500,
"upload_time": "2019-03-12T01:30:44",
"url": "https://files.pythonhosted.org/packages/fb/05/e4b8ce5f80cbc724bfe0cd0bbbc0e7798457ab0710197ffe9822e82ed6a8/lxml2json-0.2.5.tar.gz"
}
]
}