Your solution to this assignment should be uploaded to HW 4 on moodle by 11:55 PM on Wednesday, 25 February, 2015.
The objective
Even though we never talked a lot about JSON and XML encoding, you are going to write a program that produces JSON output and can be run from the terminal and used in a CGI-style RPC implementation.
This is really a pretty easy assignment if you use the right library.
The task
The big view
Your program must to stored in the filename home04 and must be runnable as a stand alone program using the hashbang.
If the user types the command similar to
./home04 brown bear red bird
your program should transform that input into a Python-style sequence, such as
[{'color': 'brown', 'animal': 'bear'}, {'color': 'red', 'animal': 'bird'}]
and then print this sequence in legal JSON
(JavaScript Object Notation).
[{"color": "brown", "animal": "bear"}, {"color": "red", "animal": "bird"}]
The user can provide an arbitrary number of arguments to
home04. If they provide an odd numbers of
arguments, your program should print the JSON object null
which corresponds to the Python object None
.
Grading
Your program should to be well-written and well-documented. In order to receive more than 50%, your program must demonstrate that it has been tested. In order to receive more than 25%, your program must be written in legal Python.
Sample output
Here is a example of what happens when I run my solution.
brock@shuttle:~$ ./home04 brown bear red bird [{"color": "brown", "animal": "bear"}, {"color": "red", "animal": "bird"}] brock@shuttle:~$ ./home04 [] brock@shuttle:~$ ./home04 brown bear red bird blue bulldog [{"color": "brown", "animal": "bear"}, {"color": "red", "animal": "bird"}, {"color": "blue", "animal": "bulldog"}] brock@shuttle:~$ ./home04 "don't" be odd null brock@shuttle:~$ ./home04 yellow "evening grosbeak" [{"color": "yellow", "animal": "evening grosbeak"}]