json to xml converter in python3

vinitkumar vinitkumar Last update: Apr 02, 2024

json2xml

image

image

image

image

Documentation Status

image

json2xml is a Python library that allows you to convert JSON data into XML format. It's simple, efficient, and easy to use.

Documentation: https://json2xml.readthedocs.io.

The library was initially dependent on the dict2xml project, but it has now been integrated into json2xml itself. This has led to cleaner code, the addition of types and tests, and overall improved performance.

Features

json2xml supports the following features:

  • Conversion from a json string to XML
  • Conversion from a json file to XML
  • Conversion from an API that emits json data to XML

Usage

You can use the json2xml library in the following ways:

Custom Wrappers and Indentation

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

Outputs this:

Omit List item

Assume the following json input

By default, items in an array are wrapped in <item></item>.

Default output:

However, you can change this behavior using the item_wrap property like this:

Outputs this:

Optional Attribute Type Support

You can also specify if the output XML needs to have type specified or not. Here is the usage:

Outputs this:

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.

How to run tests

This is provided by pytest, which is straight forward.

virtualenv venv -p $(which python3.9)
pip install -r requirements-dev.txt
python setup.py install
pytest -vv

Help and Support to maintain this project

Subscribe to our newsletter