Simple Python Library to convert JSON to XML

Overview

json2xml

Documentation Status https://coveralls.io/repos/github/vinitkumar/json2xml/badge.svg?branch=master

Simple Python Library to convert JSON to XML

Update

The dict2xml project has been forked and integrated in the project itself. This helped with cleaning up the code and also doing improvements. The goal is to remove all the dependencies from this project.

Features

It lets you convert json to xml in following ways:

  • from a json string
  • from a json file
  • from an API that emits json data

Usage

The usage is simple:

from json2xml import json2xml
from json2xml.utils import readfromurl, readfromstring, readfromjson

# get the xml from an URL that return json
data = readfromurl("https://coderwall.com/vinitcool76.json")
print(json2xml.Json2xml(data).to_xml())

# get the xml from a json string
data = readfromstring(
    '{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'
)
print(json2xml.Json2xml(data).to_xml())

# get the data from an URL
data = readfromjson("examples/licht.json")
print(json2xml.Json2xml(data).to_xml())

Custom Wrappers and indent

By default, a wrapper all and pretty True is set. However, you can change this easily in your code like this:

from json2xml import json2xml
from json2xml.utils import readfromurl, readfromstring, readfromjson

data = readfromstring(
    '{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'
)
print(json2xml.Json2xml(data, wrapper="all", pretty=True).to_xml())

Outputs this:

mojombo 1 https://avatars0.githubusercontent.com/u/1?v=4 ">
xml version="1.0" ?>
<all>
  <login type="str">mojombologin>
  <id type="int">1id>
  <avatar_url type="str">https://avatars0.githubusercontent.com/u/1?v=4avatar_url>
all>

Omit List item

By default, items in an array are wrapped in . However, you can change this easily in your code like this:

from json2xml import json2xml
from json2xml.utils import readfromurl, readfromstring, readfromjson

data = readfromstring('{"my_items":[{"my_item":{"id":1} },{"my_item":{"id":2} }]}')
print(json2xml.Json2xml(data, item_wrap=False).to_xml())

Outputs this:

1 2 ">
xml version="1.0" ?>
<all>
  <my_items type="list">
    <my_item>
        <id type="int">1id>
    my_item>
    <my_item>
        <id type="int">2id>
    my_item>
  list>
all>

Optional Attribute Type Support

Now, we can also specify if the output xml needs to have type specified or not. Here is the usage:

from json2xml import json2xml
from json2xml.utils import readfromurl, readfromstring, readfromjson

data = readfromstring(
    '{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'
)
print(json2xml.Json2xml(data, wrapper="all", pretty=True, attr_type=False).to_xml())

Outputs this:

mojombo 1 https://avatars0.githubusercontent.com/u/1?v=4 ">
xml version="1.0" ?>
<all>
  <login>mojombologin>
  <id>1id>
  <avatar_url>https://avatars0.githubusercontent.com/u/1?v=4avatar_url>
all>

The methods are simple and easy to use and there are also checks inside of code to exit cleanly in case any of the input(file, string or API URL) returns invalid JSON.

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

Comments
  • json2xml should support adding namespaces

    json2xml should support adding namespaces

    Is your feature request related to a problem? Please describe. Today json2xml does not allow you to read the namespaces as created from xml2dict

    Describe the solution you'd like I would like to see namespaces also part of xml tags

    Describe alternatives you've considered Adding namespaces manually

    Additional context https://pypi.org/project/xmltodict/

    enhancement 
    opened by userlerueda 22
  • improvements on dicttoxml

    improvements on dicttoxml

    • support of namespaces
    • moving full object serialization into loglevel debug (reduce cpu + out of mem on large objects)
    • more control parameters on xml generation: allow custom xml attributes via attr + optionally omit encapsulating xml-nodes via Flat

    Sorry, I was not able to extend your pull-request #120, thus i ceated a new one with fix for the failing test.

    opened by DirkRichter 16
  • Boolean types are not converted to their XML equivalents.

    Boolean types are not converted to their XML equivalents.

    Describe the bug When converting a JSON object with boolean type values, Json2xml is not converting the values to their XML equivalents. Json2xml should be exporting the values in the XML as the lowercase words true and false respectively. Instead, Json2xml is exporting them as Python boolean types using the capitalized words True and False.

    To Reproduce Steps to reproduce the behavior:

    1. Given the following JSON object:
    {
          "boolean": true,
          "boolean_dict_list": [
            {"boolean_dict": {"boolean": true}},
            {"boolean_dict": {"boolean": false}}
          ],
          "boolean_list": [true, false]
    }
    
    1. Calling the Json2xml conversion like so:
    xml = json2xml.Json2xml(sample_json, pretty=True).to_xml()
    
    1. Produces the following XML:
    <all>
            <boolean type="bool">True</boolean>
            <boolean_dict_list type="list">
                    <item type="dict">
                            <boolean_dict type="dict">
                                    <boolean type="bool">True</boolean>
                            </boolean_dict>
                    </item>
                    <item type="dict">
                            <boolean_dict type="dict">
                                    <boolean type="bool">False</boolean>
                            </boolean_dict>
                    </item>
            </boolean_dict_list>
            <item type="bool">True</item>
            <item type="bool">False</item>
    </all>
    

    Notice all the boolean values are capitalized instead of being lowercase like they should be in XML and JSON. There also seems to be a problem with the boolean_list array, it is missing its parent tag.

    Expected behavior

    Json2xml should produce an XML string that looks like this:

    <all>
            <boolean type="bool">true</boolean>
            <boolean_dict_list type="list">
                    <item type="dict">
                            <boolean_dict type="dict">
                                    <boolean type="bool">true</boolean>
                            </boolean_dict>
                    </item>
                    <item type="dict">
                            <boolean_dict type="dict">
                                    <boolean type="bool">false</boolean>
                            </boolean_dict>
                    </item>
            </boolean_dict_list>
            <boolean_list type="list">
                <item type="bool">true</item>
                <item type="bool">false</item>
            </boolean_list>
    </all>
    

    Additional context

    The problem with the capitalized boolean values is because of the following statements in the json2xml.dicttoxml module:

    def convert(obj, ids, attr_type, item_func, cdata, item_wrap, parent="root"):
        """Routes the elements of an object to the right function to convert them
        based on their data type"""
    
        LOG.info(f'Inside convert(). obj type is: "{type(obj).__name__}", obj="{str(obj)}"')
    
        item_name = item_func(parent)
    
        # Booleans are converted using this function because a Python boolean is a subclass of Number
        if isinstance(obj, (numbers.Number, str)):
            return convert_kv(
                key=item_name, val=obj, attr_type=attr_type, attr={}, cdata=cdata
            )
    
        if hasattr(obj, "isoformat"):
            return convert_kv(
                key=item_name,
                val=obj.isoformat(),
                attr_type=attr_type,
                attr={},
                cdata=cdata,
            )
    
        # This is never evaluated because Python booleans are subclasses of Python integers
        if isinstance(obj, bool):
            return convert_bool(item_name, obj, attr_type, cdata)
    

    Python booleans are subclasses of integers, so the boolean values are passed to convert_kv instead of convert_bool because an integer is also a numbers.Number. The following statements evaluate to True in Python:

    # Booleans are integers
    isinstance(True, int)
    
    # Booleans are numbers
    isinstance(True, numbers.Number)
    
    # Booleans are booleans
    isinstance(True, bool)
    
    bug fixed 
    opened by jbourquin 15
  • Getting an error while using pretty keyword

    Getting an error while using pretty keyword

    hi,

    i am receiving an error "TypeError: init() got an unexpected keyword argument 'pretty'"

    Details below:

    >>> print(json2xml.Json2xml(output, wrapper="result", pretty=True).to_xml())
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: __init__() got an unexpected keyword argument 'pretty'
    

    I am using python 3.7.0.

    opened by CG-ADAMS 11
  • ImportError: No module named 'src'

    ImportError: No module named 'src'

    [email protected]:~$ python3 -V Python 3.5.2 [email protected]:~$ pip3 install json2xml Collecting json2xml Downloading json2xml-1.1.0.tar.gz Collecting BeautifulSoup4==4.4.1 (from json2xml) Downloading beautifulsoup4-4.4.1-py3-none-any.whl (81kB) 100% |████████████████████████████████| 81kB 410kB/s Collecting dict2xml==1.3 (from json2xml) Downloading dict2xml-1.3.tar.gz Collecting simplejson==3.6.5 (from json2xml) Downloading simplejson-3.6.5.tar.gz (73kB) 100% |████████████████████████████████| 81kB 684kB/s Collecting six==1.9.0 (from json2xml) Downloading six-1.9.0-py2.py3-none-any.whl Collecting requests==2.9.1 (from json2xml) Downloading requests-2.9.1-py2.py3-none-any.whl (501kB) 100% |████████████████████████████████| 501kB 477kB/s Building wheels for collected packages: json2xml, dict2xml, simplejson Running setup.py bdist_wheel for json2xml ... done Stored in directory: /home/user/.cache/pip/wheels/4e/5e/51/252d1138579cf48debd311667fa57b25b0ff50177447e1906b Running setup.py bdist_wheel for dict2xml ... done Stored in directory: /home/user/.cache/pip/wheels/e6/3e/13/d3f21cf1b95a03d8d940813562b85a3a1e173774ca226c63c4 Running setup.py bdist_wheel for simplejson ... done Stored in directory: /home/user/.cache/pip/wheels/81/9e/4e/c7a8c0ce2d1e19874582fd21ae83eecf21d826582a54729394 Successfully built json2xml dict2xml simplejson Installing collected packages: BeautifulSoup4, six, dict2xml, simplejson, requests, json2xml Successfully installed BeautifulSoup4-4.4.1 dict2xml-1.3 json2xml-1.1.0 requests-2.9.1 simplejson-3.6.5 six-1.9.0 You are using pip version 8.1.1, however version 9.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. [email protected]:~$ vi 1.py [email protected]:~$ mc

    [email protected]:~$ [email protected]:~$ python3 1.py Traceback (most recent call last): File "1.py", line 1, in from src.json2xml import Json2xml ImportError: No module named 'src'

    [email protected]:~$ cat 1.py from src.json2xml import Json2xml data = Json2xml.fromjsonfile('examples/example.json').data data_object = Json2xml(data) data_object.json2xml() #xml output

    Changed file: [email protected]:~$ python3 1.py Traceback (most recent call last): File "1.py", line 1, in from json2xml import Json2xml ImportError: cannot import name 'Json2xml'

    [email protected]:~$ cat 1.py from json2xml import Json2xml data = Json2xml.fromjsonfile('examples/example.json').data data_object = Json2xml(data) data_object.json2xml() #xml output

    fixed 
    opened by patsevanton 9
  • Custom wrapper not working on 2.2.1

    Custom wrapper not working on 2.2.1

    I can't seem to make the custom Json2xml(data, WRAPPER, INDENT) to work. Keeps returning "unexpected keyword argument 'wrapper'". Also did not found any implementation of it on the json2xml.py src code.

    • OS: Windows 7 x64
    fixed 
    opened by abgrac 8
  • [Uncaught exception] UnicodeDecodeError when calling to_xml with arbitrary data

    [Uncaught exception] UnicodeDecodeError when calling to_xml with arbitrary data

    Describe the bug I found out that theJson2xml(data).to_xml() method can raise a UnicodeDecodeError leading to a crash of the running program.

    This could be problematic if users of the library are dealing with untrusted data since this issue will lead to a DoS. This should be detected and an execption should be triggered

    To Reproduce Steps to reproduce the behavior: image

    Expected behavior This execption should be expected.

    fixed 
    opened by Asteriska8 7
  • setting the xmlns value

    setting the xmlns value

    Describe the bug Currently adjusting the xmlns value is not possible as the it leads to xmlns:xmlns.

    To Reproduce Steps to reproduce the behavior:

    1. run
    from json2xml.dicttoxml import dicttoxml
    
    obj = {'bike': 'blue'}
    xml_namespace = {
        'xmlns':"http://www.w3.org/1999/xhtml"
        }
    wrapper = 'vehicle'
    xml = dicttoxml(
        obj=obj,
            custom_root=wrapper,
            attr_type=False,
            xml_namespaces=xml_namespace)
    print(xml)
    
    1. see
    <?xml version="1.0" encoding="UTF-8" ?>
    <vehicle xmlns:xmlns="http://www.w3.org/1999/xhtml">
    <bike>blue</bike>
    </vehicle>
    

    Expected behavior

    <?xml version="1.0" encoding="UTF-8" ?>
    <vehicle xmlns="http://www.w3.org/1999/xhtml">
    <bike>blue</bike>
    </vehicle>
    

    Screenshots NA

    Desktop (please complete the following information):

    • OS: macOS
    • Python : 3.9.12
    • json2xml : 3.18.0

    Additional context Add any other context about the problem here.

    opened by Jeroendevr 6
  • Replace dicttoxml as it is no longer maintained. Last commit is from 2016.

    Replace dicttoxml as it is no longer maintained. Last commit is from 2016.

    Is your feature request related to a problem? Please describe. Replace dicttoxml as it is no longer maintained. Last commit is from 2016.

    Describe the solution you'd like Any library that supports attributes as https://github.com/quandyfactory/dicttoxml/pull/66 is not merged.

    Describe alternatives you've considered https://github.com/mbj4668/pyang/blob/master/bin/json2xml

    opened by oponcea-dn 6
  • Automatically add id's to xml node for nested JSON arrays

    Automatically add id's to xml node for nested JSON arrays

    When adding a nested JSON array, automatically add id's to xml nodes

    Example JSON file:

    [
    {
        "publication_number": "EP-0477689-B1",
        "application_number": "EP-91115483-A",
        "country_code": "EP",
        "kind_code": "B1",
        "application_kind": "A",
        "application_number_formatted": "EP19910115483",
        "pct_number": "",
        "family_id": "24344316",
        "title_localized": [
          {
            "text": "Verfahren zur Herstellung eines zur Filtration geeigneten porösen Polysulfon-Mediums",
            "language": "de"
          },
          {
            "text": "Procédé de fabrication d&#39;un milieu poreux en polysulfone approprié à la filtration",
            "language": "fr"
          },
          {
            "text": "Process for the preparation of porous polysulfone media suitable for filtration",
            "language": "en"
          }
        ],
        "inventor": [
          "BEDWELL, WILLIAM B.",
          "YATES, STEPHEN F."
        ],
        "inventor_harmonized": [
          {
            "name": "BEDWELL WILLIAM B",
            "country_code": "US"
          },
          {
            "name": "YATES STEPHEN F",
            "country_code": "US"
          }
        ],
        "assignee": [
          "Cpc Engineering Corporation"
        ],
        "assignee_harmonized": [
          {
            "name": "CPC ENG CORP",
            "country_code": "US"
          }
        ],
        "entity_status": "",
        "art_unit": ""
      },
      {
        "publication_number": "EP-2309181-B1",
        "application_number": "EP-10012345-A",
        "country_code": "EP",
        "kind_code": "B1",
        "application_kind": "A",
        "application_number_formatted": "EP20100012345",
        "pct_number": "",
        "family_id": "43332270",
        "title_localized": [
          {
            "text": "Installation de chaudière à combustion à oxy-fuel et son procédé de fonctionnement",
            "language": "fr"
          },
          {
            "text": "Oxyfuel combustion boiler plant and operation method of oxyfuel combustion boiler plant",
            "language": "en"
          },
          {
            "text": "Oxyfuel-Brennkessel und Betriebsverfahren dafür",
            "language": "de"
          }
        ],
        "inventor": [
          "TANIGUCHI, MASAYUKI",
          "SHIBATA, TSUYOSHI",
          "HAYASHI, YOSHIHARU"
        ],
        "inventor_harmonized": [
          {
            "name": "TANIGUCHI MASAYUKI",
            "country_code": "JP"
          },
          {
            "name": "SHIBATA TSUYOSHI",
            "country_code": "JP"
          },
          {
            "name": "HAYASHI YOSHIHARU",
            "country_code": "JP"
          }
        ],
        "assignee": [
          "Mitsubishi Hitachi Power Systems, Ltd."
        ],
        "assignee_harmonized": [
          {
            "name": "MITSUBISHI HITACHI POWER SYS",
            "country_code": "JP"
          }
        ],
        "entity_status": "",
        "art_unit": ""
      }
    ]
    

    When converting it should automatically add id's to the nodes like below for every json array element:

    <?xml version="1.0" encoding="UTF-8" ?>
    <root>
      <row id="1">
        <publication_number>EP-0477689-B1</publication_number>
        <application_number>EP-91115483-A</application_number>
        <country_code>EP</country_code>
        <kind_code>B1</kind_code>
        <application_kind>A</application_kind>
        <application_number_formatted>EP19910115483</application_number_formatted>
        <pct_number></pct_number>
        <family_id>24344316</family_id>
        <title_localized>
          <text>Verfahren zur Herstellung eines zur Filtration geeigneten porösen Polysulfon-Mediums</text>
          <language>de</language>
        </title_localized>
        <title_localized>
          <text>Procédé de fabrication d&#39;un milieu poreux en polysulfone approprié à la filtration</text>
          <language>fr</language>
        </title_localized>
        <title_localized>
          <text>Process for the preparation of porous polysulfone media suitable for filtration</text>
          <language>en</language>
        </title_localized>
        <inventor>BEDWELL, WILLIAM B.</inventor>
        <inventor>YATES, STEPHEN F.</inventor>
        <inventor_harmonized>
          <name>BEDWELL WILLIAM B</name>
          <country_code>US</country_code>
        </inventor_harmonized>
        <inventor_harmonized>
          <name>YATES STEPHEN F</name>
          <country_code>US</country_code>
        </inventor_harmonized>
        <assignee>Cpc Engineering Corporation</assignee>
        <assignee_harmonized>
          <name>CPC ENG CORP</name>
          <country_code>US</country_code>
        </assignee_harmonized>
        <entity_status></entity_status>
        <art_unit></art_unit>
      </row>
      <row id="2">
        <publication_number>EP-2309181-B1</publication_number>
        <application_number>EP-10012345-A</application_number>
        <country_code>EP</country_code>
        <kind_code>B1</kind_code>
        <application_kind>A</application_kind>
        <application_number_formatted>EP20100012345</application_number_formatted>
        <pct_number></pct_number>
        <family_id>43332270</family_id>
        <title_localized>
          <text>Installation de chaudière à combustion à oxy-fuel et son procédé de fonctionnement</text>
          <language>fr</language>
        </title_localized>
        <title_localized>
          <text>Oxyfuel combustion boiler plant and operation method of oxyfuel combustion boiler plant</text>
          <language>en</language>
        </title_localized>
        <title_localized>
          <text>Oxyfuel-Brennkessel und Betriebsverfahren dafür</text>
          <language>de</language>
        </title_localized>
        <inventor>TANIGUCHI, MASAYUKI</inventor>
        <inventor>SHIBATA, TSUYOSHI</inventor>
        <inventor>HAYASHI, YOSHIHARU</inventor>
        <inventor_harmonized>
          <name>TANIGUCHI MASAYUKI</name>
          <country_code>JP</country_code>
        </inventor_harmonized>
        <inventor_harmonized>
          <name>SHIBATA TSUYOSHI</name>
          <country_code>JP</country_code>
        </inventor_harmonized>
        <inventor_harmonized>
          <name>HAYASHI YOSHIHARU</name>
          <country_code>JP</country_code>
        </inventor_harmonized>
        <assignee>Mitsubishi Hitachi Power Systems, Ltd.</assignee>
        <assignee_harmonized>
          <name>MITSUBISHI HITACHI POWER SYS</name>
          <country_code>JP</country_code>
        </assignee_harmonized>
        <entity_status></entity_status>
        <art_unit></art_unit>
      </row>
    </root>
    

    Here, it automatically added row id=1 row id=2 for the 2 elements which was present in the JSON array. Can we have a similar feature to add a auto-incrementing xml node for every element present in the JSON?

    fixed future 
    opened by leslyarun 6
  • remove parameters from end tag

    remove parameters from end tag

    if a tag has parameter like below end tag also has the prameter and tag name and parameter is merged by underscore.

    json 'methodName version="1.0"' : 'XXXXXXXXXXXXXXXXXXXXXXX'

    xml <methodName_version_"1.0">XXXXXXXXXXXXXXXXXXXXXXX</methodName_version_1.0>

    how can it be like this? xml <methodName version="1.0">XXXXXXXXXXXXXXXXXXXXXXX</methodName>

    question fixed 
    opened by ts-kazuo-ieiri 6
  • List items with attributes

    List items with attributes

    Concept issue

    Is your feature request related to a problem? Please describe. When creating a xml from a list and wanting to add attributes to it seems impossible.

    Describe the solution you'd like

    { 
      'vehicle' : {
          'attrs': {'transportation-mode'}, 
          '@val': ['Bike', 'Bus', 'Tram']}
    }
    

    Should result in

    <vehicle='transportation-mode'>'Bike'</vehicle>
    <vehicle='transportation-mode'>'Bus'</vehicle>
    <vehicle='transportation-mode'>'Tram'</vehicle>
    

    Describe alternatives you've considered

    • [ ] A clear and concise description of any alternative solutions or features you've considered.

    Additional context It sounds similar to issue #146 but I don't want to hijack that issue to promote my own feature request. @Estherfranssen could you confirm this would be a workable solution?

    opened by Jeroendevr 3
  • Add CodeQL workflow for GitHub code scanning

    Add CodeQL workflow for GitHub code scanning

    Hi vinitkumar/json2xml!

    This is a one-off automatically generated pull request from LGTM.com :robot:. You might have heard that we’ve integrated LGTM’s underlying CodeQL analysis engine natively into GitHub. The result is GitHub code scanning!

    With LGTM fully integrated into code scanning, we are focused on improving CodeQL within the native GitHub code scanning experience. In order to take advantage of current and future improvements to our analysis capabilities, we suggest you enable code scanning on your repository. Please take a look at our blog post for more information.

    This pull request enables code scanning by adding an auto-generated codeql.yml workflow file for GitHub Actions to your repository — take a look! We tested it before opening this pull request, so all should be working :heavy_check_mark:. In fact, you might already have seen some alerts appear on this pull request!

    Where needed and if possible, we’ve adjusted the configuration to the needs of your particular repository. But of course, you should feel free to tweak it further! Check this page for detailed documentation.

    Questions? Check out the FAQ below!

    FAQ

    Click here to expand the FAQ section

    How often will the code scanning analysis run?

    By default, code scanning will trigger a scan with the CodeQL engine on the following events:

    • On every pull request — to flag up potential security problems for you to investigate before merging a PR.
    • On every push to your default branch and other protected branches — this keeps the analysis results on your repository’s Security tab up to date.
    • Once a week at a fixed time — to make sure you benefit from the latest updated security analysis even when no code was committed or PRs were opened.

    What will this cost?

    Nothing! The CodeQL engine will run inside GitHub Actions, making use of your unlimited free compute minutes for public repositories.

    What types of problems does CodeQL find?

    The CodeQL engine that powers GitHub code scanning is the exact same engine that powers LGTM.com. The exact set of rules has been tweaked slightly, but you should see almost exactly the same types of alerts as you were used to on LGTM.com: we’ve enabled the security-and-quality query suite for you.

    How do I upgrade my CodeQL engine?

    No need! New versions of the CodeQL analysis are constantly deployed on GitHub.com; your repository will automatically benefit from the most recently released version.

    The analysis doesn’t seem to be working

    If you get an error in GitHub Actions that indicates that CodeQL wasn’t able to analyze your code, please follow the instructions here to debug the analysis.

    How do I disable LGTM.com?

    If you have LGTM’s automatic pull request analysis enabled, then you can follow these steps to disable the LGTM pull request analysis. You don’t actually need to remove your repository from LGTM.com; it will automatically be removed in the next few months as part of the deprecation of LGTM.com (more info here).

    Which source code hosting platforms does code scanning support?

    GitHub code scanning is deeply integrated within GitHub itself. If you’d like to scan source code that is hosted elsewhere, we suggest that you create a mirror of that code on GitHub.

    How do I know this PR is legitimate?

    This PR is filed by the official LGTM.com GitHub App, in line with the deprecation timeline that was announced on the official GitHub Blog. The proposed GitHub Action workflow uses the official open source GitHub CodeQL Action. If you have any other questions or concerns, please join the discussion here in the official GitHub community!

    I have another question / how do I get in touch?

    Please join the discussion here to ask further questions and send us suggestions!

    opened by lgtm-com[bot] 1
  • List items as tags with arguments

    List items as tags with arguments

    Problem

    I would like to get the following XML:

    <groceries class="foo">
        <item class="bar"/>
        <item class="foobar"/>
        <item class="barfoo"/>
    </groceries>
    

    Maybe I am missing something, but with the current implementation I can't achieve this result.

    Possible solution

    {
        "groceries": {
            "@attrs": {
                "class": "foo"
            },
            "@array": [
                {
                    "item": {
                        "@attrs": {
                            "class": "bar"
                        }
                    }
                },
                {
                    "item": {
                        "@attrs": {
                            "class": "foobar"
                        }
                    }
                },
                {
                    "item": {
                        "@attrs": {
                            "class": "barfoo"
                        }
                    }
                }
            ]
        }
    }
    
    opened by adesso-thomas-lippitsch 8
  • Multiple nested wrappers

    Multiple nested wrappers

    Is your feature request related to a problem? Please describe. I would like to convert json to xml with multiple nested wrapper like <First> <Second> . . </Second> </First>

    Describe the solution you'd like You can provide an option like to accept "," separated values or new subwrapper1 string

    Describe alternatives you've considered No

    Additional context

    open for contribution 
    opened by gvdeepak 5
Releases(3.20.0)
  • 3.20.0(Oct 16, 2022)

    What's Changed

    • fix: use SystemRandom as a secure way for generating Random Integers by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/156
    • feat: make deps more flexible by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/158

    Full Changelog: https://github.com/vinitkumar/json2xml/compare/3.19.5...3.20.0

    Source code(tar.gz)
    Source code(zip)
  • 3.19.5(Sep 18, 2022)

    What's Changed

    • fix non-failing and failing unit tests for #152 by @DirkRichter in https://github.com/vinitkumar/json2xml/pull/153
    • fix #138 and #151 + 2 new unit tests by @DirkRichter in https://github.com/vinitkumar/json2xml/pull/154

    Full Changelog: https://github.com/vinitkumar/json2xml/compare/3.19.4...3.19.5

    Source code(tar.gz)
    Source code(zip)
  • 3.19.4(Jul 24, 2022)

    What's Changed

    • feat: test new version of 3.10 and 3.11 by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/147
    • Feat/upgrade python test python311beta by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/148
    • Feat/unittest to pytest by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/149

    Full Changelog: https://github.com/vinitkumar/json2xml/compare/3.19.3...3.19.4

    Source code(tar.gz)
    Source code(zip)
  • 3.19.3(Jul 1, 2022)

    What's Changed

    • Update utils.py by @XEL-Maker in https://github.com/vinitkumar/json2xml/pull/145

    New Contributors

    • @XEL-Maker made their first contribution in https://github.com/vinitkumar/json2xml/pull/145

    Full Changelog: https://github.com/vinitkumar/json2xml/compare/3.19.2...3.19.3

    Source code(tar.gz)
    Source code(zip)
  • 3.19.2(Jun 8, 2022)

    What's Changed

    • Docs update for dicttoxml by @Jeroendevr in https://github.com/vinitkumar/json2xml/pull/140
    • chore(deps): bump waitress from 2.1.1 to 2.1.2 in /docs by @dependabot in https://github.com/vinitkumar/json2xml/pull/141
    • feat: bump python 3.10 and 3.11 version by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/142
    • escape xml char when having attrs by @Jeroendevr in https://github.com/vinitkumar/json2xml/pull/144

    Full Changelog: https://github.com/vinitkumar/json2xml/compare/3.19.0...3.19.2

    Source code(tar.gz)
    Source code(zip)
  • 3.19.0(May 19, 2022)

    What's Changed

    • feat: add types by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/125
    • Merge two dev requirements file by @Jeroendevr in https://github.com/vinitkumar/json2xml/pull/129
    • Feat/remove logging by default by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/131
    • fix: ci supports mypy now by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/132
    • Fix/types working check ci mypy by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/133
    • improved docs dicttoxml by @Jeroendevr in https://github.com/vinitkumar/json2xml/pull/134
    • add python3.11 support by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/139
    • Repeat list headers by @Jeroendevr in https://github.com/vinitkumar/json2xml/pull/138
    • Setting xsi location by @Jeroendevr in https://github.com/vinitkumar/json2xml/pull/135

    Full Changelog: https://github.com/vinitkumar/json2xml/compare/3.18.0...3.19.0

    Source code(tar.gz)
    Source code(zip)
  • 3.19.0rc1(May 6, 2022)

    What's Changed

    • feat: add types by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/125
    • Merge two dev requirements file by @Jeroendevr in https://github.com/vinitkumar/json2xml/pull/129
    • Feat/remove logging by default by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/131

    Full Changelog: https://github.com/vinitkumar/json2xml/compare/3.18.0...3.19.0rc1

    Source code(tar.gz)
    Source code(zip)
  • 3.18.0(Apr 23, 2022)

    What's Changed

    • fix: check new CI stuff like lint and coverage by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/123
    • improvements on dicttoxml by @DirkRichter in https://github.com/vinitkumar/json2xml/pull/121
    • refactor: xmltodict is only test dependency by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/124

    New Contributors

    • @DirkRichter made their first contribution in https://github.com/vinitkumar/json2xml/pull/121

    Full Changelog: https://github.com/vinitkumar/json2xml/compare/3.17.1...3.18.0

    Source code(tar.gz)
    Source code(zip)
  • 3.17.1(Apr 19, 2022)

    ## What's Changed

    • fix: issue with wrong output for boolean list by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/122

    Full Changelog: https://github.com/vinitkumar/json2xml/compare/3.17.0...3.17.1

    Source code(tar.gz)
    Source code(zip)
  • 3.17.0(Apr 18, 2022)

    What's Changed

    • chore(deps): bump waitress from 2.0.0 to 2.1.1 in /docs by @dependabot in https://github.com/vinitkumar/json2xml/pull/114
    • fix: check latest alpha by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/115
    • fix: check latest alpha by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/116
    • fix: return correct xml type for bool by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/119

    Full Changelog: https://github.com/vinitkumar/json2xml/compare/v3.16.0...3.17.0

    Source code(tar.gz)
    Source code(zip)
  • v3.16.0(Mar 5, 2022)

    What's Changed

    • Fix warning test by @Jeroendevr in https://github.com/vinitkumar/json2xml/pull/113

    New Contributors

    • @Jeroendevr made their first contribution in https://github.com/vinitkumar/json2xml/pull/113

    Full Changelog: https://github.com/vinitkumar/json2xml/compare/3.15.1...v3.16.0

    Source code(tar.gz)
    Source code(zip)
  • 3.15.1(Feb 24, 2022)

    What's Changed

    • feat: upgrade tests requirements and update metadata to show that pyp… by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/111

    Full Changelog: https://github.com/vinitkumar/json2xml/compare/3.15.0...3.15.1

    Source code(tar.gz)
    Source code(zip)
  • 3.15.0(Feb 23, 2022)

    What's Changed

    • feat: support latest version of 3.10 and 3.11 alpha3 by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/98
    • Fix/perflint by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/109
    • feat: new python versions to test against by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/110

    Full Changelog: https://github.com/vinitkumar/json2xml/compare/v3.14.0...3.15.0

    Source code(tar.gz)
    Source code(zip)
  • v3.14.0(Feb 10, 2022)

    What's Changed

    • fix: issue with uncaught UnicodeDecodeError by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/107

    Full Changelog: https://github.com/vinitkumar/json2xml/compare/3.12.0...v3.14.0

    Source code(tar.gz)
    Source code(zip)
  • 3.12.0(Jan 31, 2022)

    What's Changed

    • Do not require nor ship pytest and dependancies with json2xml by @psi29a in https://github.com/vinitkumar/json2xml/pull/104
    • Feat: install pytest separately and run pytests now by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/105

    Full Changelog: https://github.com/vinitkumar/json2xml/compare/3.10.0...3.11.0

    Source code(tar.gz)
    Source code(zip)
  • 3.10.0(Jan 29, 2022)

    What's Changed

    • Add support for Python3.11 alpha and upgrade pytest and py by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/97
    • Issue: #99 dicttoxml igores the root param by @psi29a in https://github.com/vinitkumar/json2xml/pull/100
    • fix: we support Python3.7+ now by @vinitkumar in https://github.com/vinitkumar/json2xml/pull/101

    New Contributors

    • @psi29a made their first contribution in https://github.com/vinitkumar/json2xml/pull/100

    Full Changelog: https://github.com/vinitkumar/json2xml/compare/v3.9.0...3.10.0

    Source code(tar.gz)
    Source code(zip)
  • v3.10.0rc1(Jan 1, 2022)

  • v3.9.0(Dec 18, 2021)

  • v3.8.4(Oct 23, 2021)

  • v3.8.3(Oct 23, 2021)

  • v3.8.0(Oct 6, 2021)

    • Use a better XML parsing libraries that follows better security practises.
    • Fix tox config for better local testing
    • Generate a pinned version of deps using pip-compile to have deterministic builds always.
    • Clean-up the requirements files.
    Source code(tar.gz)
    Source code(zip)
  • v3.7.0(Sep 11, 2021)

    • Forks and refactors dicttoxml inside the code itself for better maintenance. (@vinitkumar)
    • Add some new feature to be able to skip attr-type of the elements and wrapping of arrays when they are converted to xml (@jgroom33 )
    • Add support for Python 3.10
    • General clean-up and bugfixes.
    Source code(tar.gz)
    Source code(zip)
  • v3.7.0beta2(Sep 10, 2021)

    • Remove a DeprecationWarning with collections.abc
    • Add support for skipping printing item list (@jgroom33) in PR https://github.com/vinitkumar/json2xml/pull/76
    • Upgrade to Python3.10-rc2
    Source code(tar.gz)
    Source code(zip)
  • v3.7.0beta1(Aug 28, 2021)

    One of the core library that json2xml uses (dicttoxml) has been forked and included in code itself. This release is so that people can test it out this big change and report bugs if any.

    Source code(tar.gz)
    Source code(zip)
  • v3.6.0(Nov 12, 2020)

  • v3.5.0(Aug 24, 2020)

  • v3.4.1(Jun 10, 2020)

  • v3.3.3(May 30, 2020)

  • v3.3.2(Feb 5, 2020)

    This release implements the following:

    • Moved from dict2xml to a much better dicttoxml library #47 with attribute support
    • Also, fixes #34 to an extent
    • Fix issues with documentation and faulty pypi release process
    Source code(tar.gz)
    Source code(zip)
  • v3.0.0(Feb 25, 2019)

    This is a major refactor & contains some breaking changes

    Related issues: #36, #39

    • the helper methods are moved out & their naming is improved
    • the main class now only contains the method to converts to xml
    • 100% test coverage for util methods
    • custom wrapper and indent support added
    • tests integration with pytest and unittest
    Source code(tar.gz)
    Source code(zip)
Owner
Vinit Kumar
Staff Engineer at Social Schools B.V.
Vinit Kumar
JSON Schema validation library

jsonschema A JSON Schema validator implementation. It compiles schema into a validation tree to have validation as fast as possible. Supported drafts:

Dmitry Dygalo 309 Jan 01, 2023
Json utils is a python module that you can use when working with json files.

Json-utils Json utils is a python module that you can use when working with json files. it comes packed with a lot of featrues Features Converting jso

Advik 4 Apr 24, 2022
Python script to extract news from RSS feeds and save it as json.

Python script to extract news from RSS feeds and save it as json.

Alex Trbznk 14 Dec 22, 2022
A query expression for extracting data from JSON.

JSONPATH A selector expression for extracting data from JSON. Quickstarts Installation Install the stable version from PYPI. pip install jsonpath-extr

林玮 (Jade Lin) 33 Oct 22, 2022
Small python wrapper around the valico rust library to provide fast JSON schema validation.

Small python wrapper around the valico rust library to provide fast JSON schema validation.

Simon J Knibbs 5 Jul 12, 2019
JSON for Modern C++ Release Scripts

JSON for Modern C++ Release Scripts Preparations Install required tools: make install_requirements. Add required keys to config.json (apparently not c

Niels Lohmann 4 Sep 19, 2022
Wikidot-forum-dump - Simple Python script that dumps a Wikidot wiki forum into JSON structures.

wikidot-forum-dump Script is partially based on 2stacks by bluesoul: https://github.com/scuttle/2stacks To dump a Wiki's forum, edit config.py and put

ZZYZX 1 Jun 29, 2022
json|dict to python object

Pyonize convert json|dict to python object Setup pip install pyonize Examples from pyonize import pyonize

bilal alpaslan 45 Nov 25, 2022
API that provides Wordle (ES) solutions in JSON format

Wordle (ES) solutions API that provides Wordle (ES) solutions in JSON format.

Álvaro García Jaén 2 Feb 10, 2022
Marshall python objects to and from JSON

Pymarshaler - Marshal and Unmarshal Python Objects Disclaimer This tool is in no way production ready About Pymarshaler allows you to marshal and unma

Hernan Romer 9 Dec 20, 2022
jq for Python programmers Process JSON and HTML on the command-line with familiar syntax.

jq for Python programmers Process JSON and HTML on the command-line with familiar syntax.

Denis Volk 3 Jan 09, 2022
MOSP is a platform for creating, editing and sharing validated JSON objects of any type.

MONARC Objects Sharing Platform Presentation MOSP is a platform for creating, editing and sharing validated JSON objects of any type. You can use any

CASES Luxembourg 72 Dec 14, 2022
Json GUI for No Man's Sky save file

NMS-Save-Parser Json GUI for No Man's Sky save file GUI python NMS_SAVE_PARSER.py [optional|save.hg] converter only python convert.py usage: conver

2 Oct 19, 2022
A fast JSON parser/generator for C++ with both SAX/DOM style API

A fast JSON parser/generator for C++ with both SAX/DOM style API Tencent is pleased to support the open source community by making RapidJSON available

Tencent 12.6k Dec 30, 2022
Creates fake JSON files from a JSON schema

Use jsf along with fake data generators to provide consistent and meaningful fake data for your system.

Andy Challis 86 Jan 03, 2023
Convert your subscriptions csv file into a valid json for Newpipe!

Newpipe-CSV-Fixer Convert your Google subscriptions CSV file into a valid JSON for Newpipe! Thanks to nikcorg for sharing how to convert the CSV into

Juanjo 44 Dec 29, 2022
A JSON utility library for Python featuring Django-style queries and mutations.

JSON Enhanced JSON Enhanced implements fast and pythonic queries and mutations for JSON objects. Installation You can install json-enhanced with pip:

Collisio Technologies 4 Aug 22, 2022
simdjson : Parsing gigabytes of JSON per second

JSON is everywhere on the Internet. Servers spend a *lot* of time parsing it. We need a fresh approach. The simdjson library uses commonly available SIMD instructions and microparallel algorithms to

16.3k Dec 29, 2022
Editor for json/standard python data

Editor for json/standard python data

1 Dec 07, 2021
import json files directly in your python scripts

Install Install from git repository pip install git+https://github.com/zaghaghi/direct-json-import.git Use With the following json in a file named inf

Hamed Zaghaghi 51 Dec 01, 2021