Securin Inc.
Python XML JSON Test
1
1 Introduction
This assignment entails creating a simple Python program that will allow users to give arbitrary
JSON data and have it converted to XML according to the following standard.
In order to complete this assignment you must perform the following tasks.
● Provide a build script of some type to build your application.
● Provide a simple command line interface for running your program. Each of the
aforementioned items is elaborated in the following sections. In general, the more you treat
this project as though it were going to be real production code the better. You program MUST
output valid XML!
2 JSON to XML Specification
2.1 Overview
JSON does not strictly map to XML in a single way. There are many different ways one could create a
mapping from a JSON document to a XML document. This section describes the mapping that your
code MUST follow in order to be considered valid.
2.2 General Constraints
In JSON objects you are given name value pairs. This can be mapped to XML in several ways. For
this program, the XML element name corresponds to the type of the element, not the name of the
element. The name of the JSON element in a JSON object is given as an attribute on the XML
element. Only JSON array and object values may be at the top level of a file. The specifics of these
values are discussed in greater detail in later sections.
2.3 JSON Types
2
JSON supports the following types, all of which must be mapped into your XML output. Only JSON
objects and arrays are supported as top level values.
2.3.1 Number
A JSON element with a number as a value should map to an XML element named <number>, with the
number as the single and only value between the opening and closing tags. An example of this is
shown in figure 2 and 3.
2.3.2 String
A JSON element with a string as a value should map to an XML element named <string>, with the
string as the single and only value between the opening and closing tags. An example of this is shown
in figure 4 and 5.
2.3.3 Boolean
3
A JSON element with a Boolean as a value should map to an XML element named <boolean>, with
the boolean as the single and only value between the opening and closing tags. The only valid
boolean values are true and false.An example of this is shown in figure 6 and 7.
4
5
2.3.4 Array
A JSON element with an array as a value should map to an XML element named <array>. For each
element in the JSON array there should be a corresponding XML sub-element denoting the value and
type. A JSON array may contain arbitrary sub values. type. Elements of the array should not have a
name attribute. Remember, JSON arrays are not required to be homogeneous! An example of this is
shown in figure 8 and 9.
2.3.5 Object
A JSON element with an object as a value should map to an XML element named <object>. Objects
can contain arbitrary sub-values.An example of this is shown in figure 10. Objects are the only JSON
types that generate name attributes on XML tags.
6
7
8
2.3.6 null
A JSON element with an null as a value should map to an XML element named <null/>. Unlike other
XML representations for JSON values, a null value does not have a closing tag, rather it is self-closing
by adding a forward slash before the end of the element tag. An example of this is shown in figure 11
and 12.
2.3.7 Examples
Besides the examples shown here, there are example files in the examples/ folder in the archive with
which you were provided. These were generated with our own reference implementation. If anything
in those files seems to not match up with this document, please contact us and let us know.
3 Python Code
3.1 Open Source Libraries
You may use any open source libraries to help you accomplish this project without any restrictions,
however You must either include these libraries in your submitted code, or have them automatically
downloaded through your build tool.
3.2 CLI
Your program must have a very simple command line interface. The first argument is taken to be the
path to the input JSON file and the second argument is taken to be the path to the XML output file.
9
Any other number of arguments should print an usage message. The XML file may or may not exist,
but the path must be valid.
3.3 Test and Auxiliary Files
If you use or create any test files or any other auxiliary files as part of your submission, we would very
much like to inspect those as well. Please include them in the submission.
4.4 README
Make sure to include a README file in your project that explains how to build and run your project.
Please name this file README, please make sure that it is in plain text format, and please place it in
the root (top-level) of your project turn in. This file must explain exactly how to build and run your
project.It must also list all libraries that you used, including a URL so that we can look them up. You
may include a short writeup in this file describing your general design motivations. Please mention the
location and purpose of any test or auxiliary files you have included in your submission.
5 Submitting Your Project
Please submit your project as a .zip, .tar.gz, .tar.bz, or .tar.xz. Please do not include any compiled
code, unless it is an library.
6 Questions
If you have any questions or need clarification about anything please feel free to send an email
10