Simple Python Library to convert JSON to XML
Project description
json2xml
Simple Python Library to convert JSON to XML
Free software: Apache Software License 2.0
Documentation: https://json2xml.readthedocs.io.
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:
<?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>
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file json2xml-3.3.3.tar.gz
.
File metadata
- Download URL: json2xml-3.3.3.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d26b61409560b7fc6749e632dddbdf879f6e6654429f899b63aee7f02a46d1c |
|
MD5 | b6bc8fbb8a775b9fe78d7c7370c41a8d |
|
BLAKE2b-256 | afb341e2cc96ff4f0640237367e4248bf9eaf0b07634e8665a739fdd1fd437ad |
File details
Details for the file json2xml-3.3.3-py2.7.egg
.
File metadata
- Download URL: json2xml-3.3.3-py2.7.egg
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1491a30a86a2de8711be8b94b4c1940b77c184961de72dc3ca20079ee93419b3 |
|
MD5 | 64341d1adab75dadc1b379d5a751a9ce |
|
BLAKE2b-256 | 5e3bb0db3e82b7042272bd039f69145af3af734206d2142f124afe0bcca454d6 |