Metadata-Version: 2.1
Name: json2xml
Version: 3.8.2
Summary: Simple Python Library to convert JSON to XML
Home-page: https://github.com/vinitkumar/json2xml
Author: Vinit Kumar
Author-email: mail@vinitkumar.me
License: Apache Software License 2.0
Keywords: json2xml
Platform: UNKNOWN
Classifier: Development Status :: 6 - Mature
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
License-File: LICENSE
License-File: AUTHORS.rst
Requires-Dist: attrs (==21.2.0)
Requires-Dist: certifi (==2021.5.30)
Requires-Dist: charset-normalizer (==2.0.6)
Requires-Dist: defusedxml (==0.7.1)
Requires-Dist: idna (==3.2)
Requires-Dist: importlib-metadata (==4.8.1)
Requires-Dist: iniconfig (==1.1.1)
Requires-Dist: packaging (==21.0)
Requires-Dist: pluggy (==1.0.0)
Requires-Dist: py (==1.10.0)
Requires-Dist: pyparsing (==2.4.7)
Requires-Dist: pytest (==6.2.5)
Requires-Dist: requests (==2.26.0)
Requires-Dist: toml (==0.10.2)
Requires-Dist: typing-extensions (==3.10.0.2)
Requires-Dist: urllib3 (==1.26.7)
Requires-Dist: xmltodict (==0.12.0)
Requires-Dist: zipp (==3.6.0)

========
json2xml
========


.. image:: https://img.shields.io/pypi/v/json2xml.svg
        :target: https://pypi.python.org/pypi/json2xml
.. image:: https://github.com/vinitkumar/json2xml/actions/workflows/pythonpackage.yml/badge.svg
.. image:: https://img.shields.io/pypi/pyversions/json2xml.svg
.. image:: https://badge.fury.io/py/json2xml.svg
.. image:: https://readthedocs.org/projects/json2xml/badge/?version=latest
        :target: https://json2xml.readthedocs.io/en/latest/?badge=latest
        :alt: Documentation Status
.. image:: https://coveralls.io/repos/github/vinitkumar/json2xml/badge.svg?branch=master
     :target: https://coveralls.io/github/vinitkumar/json2xml?branch=master


Simple Python Library to convert JSON to XML

* Free software: Apache Software License 2.0
* Documentation: https://json2xml.readthedocs.io.


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:


.. code-block:: python

    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:

.. code-block:: python

    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:

.. code-block:: xml

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

Omit List item
--------------

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

.. code-block:: python

    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:

.. code-block:: xml

    <?xml version="1.0" ?>
    <all>
      <my_items type="list">
        <my_item>
            <id type="int">1</id>
        </my_item>
        <my_item>
            <id type="int">2</id>
        </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:

 .. code-block:: python

    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:

.. code-block:: xml

    <?xml version="1.0" ?>
    <all>
      <login>mojombo</login>
      <id>1</id>
      <avatar_url>https://avatars0.githubusercontent.com/u/1?v=4</avatar_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.

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage


=======
History
=======

===================
v3.8.0 / 2021-10-07
===================

  * Feat/security improvements (#81)
  * :arrow_up: feat: python 3.10 released (#79)

===================
v3.7.0 / 2021-09-11
===================

  * :bookmark: feat: final release for v3.7.0
  * :bookmark: feat: bump version

========================
v3.7.0beta2 / 2021-09-10
========================

  * Feat/cleanup and deprecation fix (#78)
  * item ommision (#76)
  * Create FUNDING.yml

========================
v3.7.0beta1 / 2021-08-28
========================

  * Feat/fork and update dict2xml (#75)
  * chore(deps-dev): bump pip from 18.1 to 19.2 (#73)
  * Delete .travis.yml
  * chore(deps-dev): bump lxml from 4.6.2 to 4.6.3 (#68)
  * Bump lxml from 4.1.1 to 4.6.2 (#66)

===================
v3.6.0 / 2020-11-12
===================

  * Feat/wip exceptions (#65)
  * Add .deepsource.toml
  * feat: upgrade the actions
  * feat: try & support more os and python versions
  * Update pythonpackage.yml

===================
v3.5.0 / 2020-08-24
===================

  * feat: remove six as dependency as we are python3 only, resolves #60 (#61)
  * feat: update makefile for the correct command

===================
v3.4.1 / 2020-06-10
===================

  * fix: issues with pypi release and bump version
  * Feat/attr type docs (#58)
  * fix: conflicts
  * Feat/attr type docs (#57)
  * Merge github.com:vinitkumar/json2xml
  * Update json2xml.py (#56)
  * Merge github.com:vinitkumar/json2xml
  * feat: fix typo in the readme

===================
v3.3.3 / 2020-02-05
===================

  * Update README.rst
  * fix: issue with pypi uploads
  * fix: version
  * bump version
  * Update pythonpackage.yml
  * Refactor/prospector cleanup (#50)
  * Update pythonpackage.yml
  * Create pythonpackage.yml
  * Update README.rst
  * fix: typo in readme
  * bump version
  * Feature/attribute support (#48)
  * Feature/attribute support (#47)
  * chore: bump version
  * fix: remove print statement in json read because it confuses people
  * fix typo in readme

===================
v3.0.0 / 2019-02-26
===================

  * Fix/coveralls (#43)
  * update coverage report (#42)
  * Merge pull request #41 from vinitkumar/fix/coveralls
  * add python coveralls
  * Merge pull request #40 from vinitkumar/refactor/cookiecutter
  * update coverage
  * add image for coveralls
  * coverage and coveralls integrations
  * try and trigger coveralls too
  * fix code block in readme
  * add doc about custom wrapper
  * try at reducing the dependencies
  * add tests for custom wrappers as well
  * add tests for actualy dict2xml conversion
  * fix: remove missing import
  * fix: code syntax highlight in the readme again
  * fix: code syntax highlight in the readme again
  * fix: code syntax highlight in the readme
  * chore: update readme with code samples
  * test: add testcases for the different utils method
  * remove unused imports
  * check the third method for generating dict from json string too
  * run correct test files
  * fix tests
  * update requirements and setuptools
  * refactor the module into more maintainable code
  * chore: add boilerplate
  * remove all legacy
  * Fix/cleanup (#38)
  * cleanup: remove unused modules (#37)
  * Merge pull request #35 from vinitkumar/improve-structure
  * cleanup
  * one again try to get the build working
  * travis need full version for latest supported python
  * do not hardcode version in a series
  * update grammar
  * fix conflicts
  * Update LICENSE
  * cleanup readme
  * remove cli
  * some cleanup and update the tests
  * Update readme.md
  * Cleanup Readme.md
  * Update issue templates
  * fix vulnerabilities in requests


