Skip to main content

Simple Python Library to convert JSON to XML

Project description

json2xml

https://img.shields.io/pypi/v/json2xml.svg https://img.shields.io/travis/vinitkumar/json2xml.svg Documentation Status Updates https://coveralls.io/repos/github/vinitkumar/json2xml/badge.svg?branch=master

Simple Python Library to convert JSON to XML

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, 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 defualt, a wrapper all and indent 2 is set. However, you can change this easily in your code like this:

from json2xml import json2xml, readfromurl, readfromstring, readfromjson
data = readfromstring(
    '{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'
)
print(json2xml.Json2xml(data, wrapper="custom", indent=8).to_xml())

Outputs this:

<custom>
    <avatar_url>https://avatars0.githubusercontent.com/u/1?v=4</avatar_url>
    <id>1</id>
    <login>mojombo</login>
</custom>

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.

History

3.0.0 (2019-02-22)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

json2xml-3.0.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

json2xml-3.0.0-py2.py3-none-any.whl (4.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file json2xml-3.0.0.tar.gz.

File metadata

  • Download URL: json2xml-3.0.0.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for json2xml-3.0.0.tar.gz
Algorithm Hash digest
SHA256 190cf2a54fae37c045da87b056bf3bfaf2d5cd10a8abb5c0d4430b359bb81c92
MD5 62726967438cbee9483e45a6911dd214
BLAKE2b-256 af24393a1938cdfc2defafcfbe06f85c7759a2d55be8bf015cc88938fd4d5a5c

See more details on using hashes here.

File details

Details for the file json2xml-3.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: json2xml-3.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for json2xml-3.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1dd5e8721d4d915c4678f7cfe60e546ebe8ecc94392a7a0347c4da47ce57cbd6
MD5 63362fc1a1e2881ba1c99acaf95cf651
BLAKE2b-256 24d04ec37049b419f71063839c9c5b87fc016b11cf3dd9aa99aa17949166fc38

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page