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 default, 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.1.tar.gz (9.2 kB view details)

Uploaded Source

Built Distributions

json2xml-3.0.1-py3.7.egg (5.7 kB view details)

Uploaded Source

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

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: json2xml-3.0.1.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.2

File hashes

Hashes for json2xml-3.0.1.tar.gz
Algorithm Hash digest
SHA256 90a80d9a0fef0465f0a5076bd3d64444ed453b86bf0aff035ce552bb3a05d40b
MD5 8b65577cf97f8ab01b66ad6803a2be4d
BLAKE2b-256 90b5c76f72172c02091d4a9fd720ebf0de6875080a63ec321bd9ecae9ee0d875

See more details on using hashes here.

File details

Details for the file json2xml-3.0.1-py3.7.egg.

File metadata

  • Download URL: json2xml-3.0.1-py3.7.egg
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.2

File hashes

Hashes for json2xml-3.0.1-py3.7.egg
Algorithm Hash digest
SHA256 5cee9308c39c922500bf884c839d0738dddcb90da4571fb57dbb24bde8769d58
MD5 08509cd0315dfdbb6fb1a5b4ff00fd86
BLAKE2b-256 99818657ee531d6cefd69fe11e37da4ebca39bd6f33fbdfc811696c347e5a070

See more details on using hashes here.

File details

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

File metadata

  • Download URL: json2xml-3.0.1-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.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.2

File hashes

Hashes for json2xml-3.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 beacf4cf367c40fc2dac8b5d4f196347c5a50244951cb8f9120965167a7d48cf
MD5 8ed198cdbb4a51575f1378dd6aa40898
BLAKE2b-256 4e3bcf71665e917c83e0a380e98181b4b7819d513883912f0ea65c0e23d020e9

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