Skip to content

A sample Django application of an xml to json converter

Notifications You must be signed in to change notification settings

samukasmk/django_xml2json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django_xml2json

An online XML to JSON conversion and validation tool

Live demo 🔍

You can see on live demo here: http://smksamuka.pythonanywhere.com/

.docs/django_xml2json-use.gif

Install 🧑🏽‍💻

Execute commands on terminal:

# clone this repository
git clone https://github.com/samukasmk/django_xml2json.git

# access new folder
cd django_xml2json

# create new virtualenv
python3 -m venv ./venv
source ./venv/bin/activate

# install required libraries
pip install -r requirements.txt

# run the webserver (in developement mode)
./manage.py runserver

.docs/django_xml2json-install.gif

Using web app 📃

Access the URL from your local: http://127.0.0.1:8000/connected/

And enjoy it! 🎉

Parsing by Rest Framework API 🌐

Create a sample file:

cat > address.json << EOF
<?xml version="1.0"?>
<Root>
    <Address>
        <StreetLine1>123 Main St.</StreetLine1>
        <StreetLine2>Suite 400</StreetLine2>
        <City>San Francisco</City>
        <State>CA</State>
        <PostCode>94103</PostCode>
    </Address>
    <Address>
        <StreetLine1>400 Market St.</StreetLine1>
        <City>San Francisco</City>
        <State>CA</State>
        <PostCode>94108</PostCode>
    </Address>
</Root>
EOF

Upload with curl command:

curl -F [email protected] http://127.0.0.1:8000/api/converter/convert/       
{"Root":[{"Address":[{"StreetLine1":"123 Main St."},{"StreetLine2":"Suite 400"},{"City":"San Francisco"},{"State":"CA"},{"PostCode":"94103"}]},{"Address":[{"StreetLine1":"400 Market St."},{"City":"San Francisco"},{"State":"CA"},{"PostCode":"94108"}]}]}

Testing 🛠️

You can run tests my django manage command:

./manage.py test
Found 22 test(s).
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
......................
----------------------------------------------------------------------
Ran 22 tests in 0.088s

OK
Destroying test database for alias 'default'...

Or run a specific test with python unittest library

DJANGO_SETTINGS_MODULE=exercise.tests_settings python -m unittest -k xml_converter.tests.XMLConversionTestCase.test_connected_convert_addresses
.
----------------------------------------------------------------------
Ran 1 test in 0.195s

OK

About

A sample Django application of an xml to json converter

Resources

Stars

Watchers

Forks

Packages

No packages published